2014-11-21 88 views
8

我正在使用以下代码从加密狗发送短信。 它发送Sucessfullly。 现在我想读加密狗SIM卡的短信或者未读短信这样plaese任何一个可以告诉我如何阅读如何使用JAVA从加密狗中的SIM读取短信

以下是发送短信代码

import org.smslib.OutboundMessage; 
import org.smslib.Service; 
import org.smslib.modem.SerialModemGateway; 

... 

private String port = "COM4";   // Modem Port. 
private int bitRate = 9600;   // This is also optional. Leave as it is. 
private String modemName = "ZTE";  // This is optional. 
private String modemPin = "0000";  // Pin code if any have assigned to the modem. 
private String SMSC = "+919822078000"; // Message Center Number ex. Mobitel 

... 

SerialModemGateway gateway = new SerialModemGateway("", port, 9600, "InterCEL", ""); 
Service.getInstance().addGateway(gateway); 
Service.getInstance().startService(); 
// System.out.println("center number=" + gateway.getSmscNumber()); 
gateway.setSmscNumber(SMSC); 
gateway.setOutbound(true); 

OutboundMessage o = new OutboundMessage(number, str); 
gateway.sendMessage(o); 

有InboundMessage类,它有三个参数sunch作为网关,MemoryIndexNumber,SimMemoryLocation对此我无法得到,因此如果从电子狗的SIM卡读取短信任何其他方式返回null

InboundMessage n=new InboundMessage() 
gateway.readMessage(n); 

回答

6

要在SIM卡存储当前阅读的邮件,你可以做

ArrayList<InboundMessage> msgList = new ArrayList<InboundMessage>(); 
Service.getInstance().readMessages(msgList, InboundMessage.MessageClasses.ALL); 
for (InboundMessage im : msgList) { 

} 

但要做到传入邮件的实时检测,则需要实现org.smslib.IInboundMessageNotification

例如

import org.smslib.AGateway; 
import org.smslib.IInboundMessageNotification; 
import org.smslib.InboundMessage; 
import org.smslib.Message.MessageTypes; 

public class SMSInNotification implements IInboundMessageNotification 
{ 
    public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg) 
    { 
     switch (msgType) 
     { 
      case INBOUND: 
       System.out.println(">>> New Inbound message detected from " + "+" + msg.getOriginator() + " " + msg.getText()); 
       break; 
      case STATUSREPORT: 

       break; 
     } 
    } 
} 

然后与.startService启动服务()

gateway.setInbound(true); 
Service.getInstance().setInboundMessageNotification(new SMSInNotification()); 

你可以阅读更多的文档中在github https://github.com/smslib/smslib-v3/tree/master/doc

+0

首先感谢现在我能够前行运行这些阅读邮件,但notifiaction不工作我已经做了同样的想你说,但我没有得到任何输出,当我收到短信请你能告诉我如何再次。我做了以下方法是正确的SerialModemGateway网关=新SerialModemGateway(“”,端口名称,9600,“InterCEL”,“”); gateway.setInbound(true); Service.getInstance()。setInboundMessageNotification(new SMSInNotification()); \t \t Service.getInstance()。addGateway(gateway); \t \t Service.getInstance()。startService(); – pareshm 2014-11-27 04:19:57

+0

我从我发布的通知类中删除了自己的处理代码。所以它不会输出任何东西。你自己添加了一些处理代码吗? – Phil 2014-11-27 19:36:46

+0

我已更新我的答案,使其更清晰我的意思 – Phil 2014-11-27 21:12:54