2014-11-21 39 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