02-20-2013 05:32 AM
hello.. i'm new on bb development. i want to create app that listen to sms message and then show it to screen using labelfield.
i try to implement code from this link http://www.blackberry.com/developers/docs/7.1.0api
and here is my code:
package smslistening;
import javax.microedition.io.Connector;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class PesanScreen extends MainScreen{
LabelField pesan;
public PesanScreen(){
super();
setTitle("sms receiver");
MessageConnection _mc = (MessageConnection)Connector.open("sms://:0");
for(;;)
{
Message m = _mc.receive();
String address = m.getAddress();
String msg = null;
if ( m instanceof TextMessage )
{
TextMessage tm = (TextMessage)m;
msg = tm.getPayloadText();
pesan = new LabelField(msg);
}
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");
pesan = new LabelField(msg);
}
else
{
// System.out.println("Invalid Message Format");
// System.out.println("Received SMS text from " + address + " : " + msg);
pesan = new LabelField("invalid format");
}
}
}
}code above show me an error on eclipse that said "BinaryMessage" cannot be resolve to a type.
please help me how i can implement the sample code in this link http://www.blackberry.com/developers/docs/7.1.0api
02-20-2013 05:40 AM
02-20-2013 05:51 AM
thank you for your reply.. but i still can't understand it.
should i put the code on separate class? and how to call it from main class? please help me with complete code
02-20-2013 06:02 AM
02-20-2013 06:08 AM
There is a bit of learning curve to understand Blackberry coding and the way you do things.
I for one think sample code is useful to illustrate specific points, but in this case any sample code you got would most likely confuse rather than enlighten. Giving you a full sample at this stage is a little like asking you to learn to drive in a Formula 1 car.
So I think you need to get a basic application working, then extend it.
One of the main things you need to understand is Threading in general and the Blackberry Event Tread specifically. Threading is a standard, so most books and courses will talk about it. I presume that you know how to do Threading.
The Event Thread is a UI construct similar to that used in Swing (and in fact in Cascades for BB10 but that is a different story). Here is a good introduction to it:
http://supportforums.blackberry.com/t5/Java-Develo
You will find more if you search.
Now in your case you have a background process that you want to use to update the user Interface. The place I suggest you start doing this is httpDemo, which is a sample that should come with your SDK. So you can review that to understand a little more about the Event Thread and Threading in general. Then play with it to make changes.
Once you have that under your belt, then you can look at replacing the network interaction with your SMS interaction.
I recommend that you spend a lot of time reviewing the developer document too. The new web site is actually very good, significantly better than when I started! Start here
http://developer.blackberry.com/java/