我试着用在电脑上接收短信.我已经在这个链接上找到了解决我的问题的方法,但是现在我面临的问题是,我已经收到了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);
}
}
}
}发布于 2015-12-08 06:06:19
有一次,我也面临着同样的问题,而我的要求是保存所有传入消息的记录。因此,我在数据库中创建了表,并将所有传入的消息插入到数据库中,并提供了完整的详细信息,例如发件人号、消息内容以及日期和时间。在数据库中,我结合了日期、时间和消息内容,做出了独特的记录。
现在,如果我将收到重复的消息,那么确定日期、时间和消息内容将是相同的。之后,当这些值被插入到数据库中时,重复的值将不会插入到数据库中。因此,我们将有独特的数据。
但这可能不适用于您,因为实际上您没有多次接收消息,您只收到一条消息,然后在通知时多次向您显示。因为如果您将多次收到消息,则日期和时间必须始终不同。但就我而言,这些都是一样的。因此,首先您应该尝试删除收件箱中的所有消息,然后可能需要刷新接收端口。
发布于 2015-08-26 03:08:49
也经历过这个问题。那些笨蛋要了我的命。我不知道您为什么要为此编写代码,但我所做的只是将收件箱和发件箱保存到数据库中(当入站通知到达时),然后从GSM的收件箱中删除消息。我不再收到大量的通知。它很有效,但它并不能真正解决问题。只是个解决办法。
我觉得这和港口有关。也许它需要冲洗什么的。不确定,我还没有那么好的程序员。
希望这个解决办法能帮上忙!干杯!
https://stackoverflow.com/questions/27587348
复制相似问题