D-Link USB モデムを使用してコンピュータで SMS を受信しようとしています。このリンクで問題の解決策を見つけましたが、 今直面している問題は、このように同じメッセージを 3 回受信していることです。
New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello
また、プログラムが長時間開いたままになっていると、上記の行が画面に何度も印刷されます。Google で何度も検索しましたが、未使用の通知を削除する提案が見つかった場所もあります。それを実行しましたが、まだメッセージが重複しています受け取った。コードを以下に示します
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);
}
}
}
}