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
Contributor
Sulist
Posts: 48
Registered: ‎06-17-2011
My Device: Blackberry 9800

REceive sms

I'm making an application that can receive sms with the code below: 

 

package mypackage;

import java.io.IOException;

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerException;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen implements MessageListener
{
    MessageConnection sambung ;
    EditField isi ;
    /**
     * Creates a new MyScreen object
     */
    public MyScreen( )
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
        isi = new EditField("","");
        add(isi);
        try {
            this.sambung = (MessageConnection)Connector.open("sms://");
            this.sambung.setMessageListener(this);
        }
        catch (Exception e)
        {
            System.out.println("Exception: " + e);
        }
    }
    public void notifyIncomingMessage(final MessageConnection sambung) {
        new Thread ()
        {
            MessageConnection conn;
            Thread set (MessageConnection conn){
            this.conn =conn ;
            return this;
            }
            public void run (){
                try {
                    TextMessage pesan = (TextMessage)conn.receive();
                    String perintah = pesan.getPayloadText();
                    isi.setText(perintah);
                }catch (IOException e) {
                    System.out.println("ExceptionMessage :"+e);
                } catch (ApplicationManagerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }.set(sambung).start();
    }
}

 

 

But when I try the application on the device is actually on editfield can not display a currently received sms. Can someone can give me a correction to the source code .

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: REceive sms

I presume you are seeing an IllegalStateException, on this line:

                   isi.setText(perintah);
 

in which case replace this line with something like:

UiAPplication.getUiApplication().invokeLater(new Runnable() {

public void run() {

isi.setText(perintah);

}

});

 

You might have to create sdome "final" references to get this to compile. 

 

If this is not the problem you are seeing, can you please describe what happens exactly?

 

 

Contributor
Sulist
Posts: 48
Registered: ‎06-17-2011
My Device: Blackberry 9800

Re: REceive sms

Thanks for your respond sir , my application consists of a editfieldand if an incoming sms content will appear in the editfield  and I've tried your suggestion but no effect

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: REceive sms

So when debugging and stepping through the code, what exactly happens?