8

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

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 n=new InboundMessage()
gateway.readMessage(n);

If there is any other way to read sms from SIM of dongle.

Samiron
  • 5,169
  • 2
  • 28
  • 55
pareshm
  • 4,874
  • 5
  • 35
  • 53

1 Answers1

6

To read the messages currently in the SIM memory, you can just do

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

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

Then run these before the line which starts the service with .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

Phil
  • 1,996
  • 1
  • 19
  • 26
  • Firstly Thanks now i am able to read the messages but notifiaction is not working i have done same think you said but i am not getting any output when i recieve the sms please can you tell me how to to again . i have done the following way is it right SerialModemGateway gateway = new SerialModemGateway("", portname,9600, "InterCEL", "");gateway.setInbound(true); Service.getInstance().setInboundMessageNotification(new SMSInNotification()); Service.getInstance().addGateway(gateway); Service.getInstance().startService(); – pareshm Nov 27 '14 at 04:19
  • I removed my own handling code from that notification class i posted. So it won't output anything. Did you add some handling code yourself? – Phil Nov 27 '14 at 19:36
  • I have updated my answer to make it clearer what I mean – Phil Nov 27 '14 at 21:12
  • I have also written same thing but it is not entering process function on receiving sms – pareshm Nov 28 '14 at 16:45
  • Please can you increase your log4j level and give me some logs to look at? The logging looks quite verbose so I think it will highlight the problem. – Phil Nov 29 '14 at 00:11
  • when i am sending sms from mobile to dongle sim then the notifiction class sholud get called automatically means it sholud enter process function but its not entering the process function – pareshm Dec 01 '14 at 09:38
  • Yes it should. Please give logs. Maybe a misconfiguration on your end or a bug in the library. – Phil Dec 01 '14 at 13:18
  • I have never used logs how i will provide you the logs – pareshm Dec 02 '14 at 11:59