How to read SMS from a sim in keys using JAVA

I use the following code to send sms from a key. Its dispatch is sucessfullly. Now I want to read SIM sms or unread sms from the key, so plaese can someone tell me how to read that

Below is the code for sending 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 an InboundMessage class that takes three sunch parameters like gateway, MemoryIndexNumber, SimMemoryLocation, which I cannot get to return null

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

If there is another way to read SMS from a SIM card key.

+8
java smslib
source share
1 answer

To read the messages stored in the SIM card memory, you can simply do

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

But for direct detection of incoming messages you need to implement 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 them before the line that starts the service using .startService ()

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

You can read more in the github documentation https://github.com/smslib/smslib-v3/tree/master/doc

+6
source share

All Articles