Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Member
Posts: 3
Registered: ‎07-27-2012
My Device: 8520
My Carrier: Airtel

SMS listner

How attatch a sms listner on incoming sms?

New Developer
Posts: 21
Registered: ‎07-26-2012
My Device: 9790
My Carrier: airtel

Re: SMS listner

MessageConnection _mc = (MessageConnection)Connector.open("sms://:0"); 
_mc.setMessageListener(this);



public void notifyIncomingMessage(MessageConnection conn) {
Message m = _mc.receive();
String address = m.getAddress();
String msg = null;
if ( m instanceof TextMessage )
{
TextMessage tm = (TextMessage)m;
msg = tm.getPayloadText();
}
else if (m instance of BinaryMessage) {
StringBuffer buf = new StringBuffer();
byte[] data = ((BinaryMessage) m).getPayloadData();

// convert Binary Data to Text
msg = new String(data, "UTF-8");
}
else
System.out.println("Invalid Message Format");
System.out.println("Received SMS text from " + address + " : " + msg);
}
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: SMS listner

Use filter also so u can listen only particular sms

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.