我正在使用以下代码从加密狗发送短信。 它的发送成功。 现在我想从加密狗读取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我无法获取所以它返回null
InboundMessage n=new InboundMessage()
gateway.readMessage(n);
如果还有其他方法可以从加密狗的SIM中读取短信。
答案 0 :(得分:6)
要阅读SIM内存中当前的消息,您可以执行
ArrayList<InboundMessage> msgList = new ArrayList<InboundMessage>();
Service.getInstance().readMessages(msgList, InboundMessage.MessageClasses.ALL);
for (InboundMessage im : msgList) {
}
但要对传入的消息进行实时检测,您需要实现org.smslib.IInboundMessageNotification
E.g。
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