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
manish1109
Posts: 3
Registered: ‎07-27-2012
My Device: 8520

SMS listner

How attatch a sms listner on incoming sms?

Please use plain text.
New Developer
ajaysinghBB
Posts: 21
Registered: ‎07-26-2012
My Device: 9790

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);
}
Please use plain text.
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10

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.
-------------------------------------------------------------------------------------.
Please use plain text.