简体   繁体   English

如何使用JAVA从加密狗的SIM读取短信

[英]How to read SMS from sim in dongle using JAVA

I am using following code to send sms from dongle. 我正在使用以下代码从加密狗发送短信。 Its sending Sucessfullly. 它的发送成功。 Now I want to read SIM sms or unread sms from dongle so plaese can any one tell me how to read that 现在我想从加密狗读取SIM短信或未读短信,所以任何人都可以告诉我如何阅读

following is the code to send sms 以下是发送短信的代码

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);

There is InboundMessage class which takes three parameters sunch as gateway, MemoryIndexNumber, SimMemoryLocation which I am unable to get so it returns null InboundMessage类有三个参数sunch作为网关,MemoryIndexNumber,SimMemoryLocation我无法获取所以它返回null

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

If there is any other way to read sms from SIM of dongle. 如果有任何其他方式从加密狗的SIM读取短信。

To read the messages currently in the SIM memory, you can just do 要读取SIM内存中当前的消息,您可以这样做

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

}

But to do live detection of incoming messages, you need to implement org.smslib.IInboundMessageNotification 但是要对传入的消息进行实时检测,您需要实现org.smslib.IInboundMessageNotification

Eg 例如

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;
        }
    }
}

Then run these before the line which starts the service with .startService() 然后在使用.startService()启动服务的行之前运行这些

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

You can read more in the documentation on github https://github.com/smslib/smslib-v3/tree/master/doc 您可以在github上的文档中阅读更多内容https://github.com/smslib/smslib-v3/tree/master/doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM