I am trying to receive sms on computer using D-Link USB Modem. I have find out solution of my problem on this link But now issue i am facing is that i am receiving same message 3 times, like this
New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello
Also if program remains open for long time then these above given lines will be printed on screen again and again I did search on google a lot and some where a suggestion i found to remove unused notification, i have done that but still duplicate messages are being received. Code is given below
public void doIt() throws Exception{
InboundNotification inboundNotification = new InboundNotification();
try{
SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM7", 921600, "", "");
gateway.setProtocol(Protocols.PDU);
gateway.setInbound(true);
gateway.setSimPin("0000");
Service.getInstance().setInboundMessageNotification(inboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println("Now Sleeping - Hit <enter> to stop service.");
System.in.read();
System.in.read();
}catch (Exception e){
e.printStackTrace();
}finally{
Service.getInstance().stopService();
}
}
public class InboundNotification implements IInboundMessageNotification{
public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg){
if (msgType == MessageTypes.INBOUND) {
System.out.println("New Inbound message detected from Gateway: " + msg.getOriginator() + " " + msg.getText());
try {
gateway.deleteMessage(msg);
} catch (GatewayException ex) {
Logger.getLogger(ReadMessages.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}