Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
dinu_hasith
Posts: 15
Registered: 10-23-2008

Receiving incoming connections when midlet is running

Hi,

I have a midlet that listens for incoming sms connections on sms://:50001. I use static push registration to auto start the midlet when a sms is received. That works fine. When the  midlet is running, I have a separate thread listening for sms on sms://:50001. This however does not work.

 

What happens is, I get a notification asking whether to start the midlet, even though it is already running. And my thread cant receive the sms. The midlet works fine when push registration is removed.

 

I've tested on two blackberry 8310, one with OS version 4.2 other with version 4.5. The midlet works fine in OS 4.2.

 

my code

 

 

public final class PushRegistryApp extends MIDlet { //The data we expect to receive. private static final String TEST_DATA = "This is just a test"; private Display theDisplay; private Form theForm; private StringItem messages; private MessageConnection mc; public PushRegistryApp() { } //Signals the MIDlet that it has entered the Active state. public void startApp() { //Get the display object for this MIDlet. theDisplay = Display.getDisplay(this); //Instantiate the form. theForm = new Form("PushRegistryApp"); //Istantiate the StringItem. messages = new StringItem("", "starting..."); //Add the StringItem to the form. theForm.append(messages); //Open the SMS connection on port 5678. try { mc = (MessageConnection) Connector.open("sms://:50001"); } catch (IOException ioe) { message("Failed to open connection: " + ioe.toString()); System.out.println("Failed to open connection: " + ioe.toString()); } //Create and start a new WorkerThread. Thread t = new WorkerThread(); t.start(); theDisplay.setCurrent(theForm); } private class WorkerThread extends Thread { public void run() { try { BinaryMessage txtMsg = (BinaryMessage) mc.receive(); message("Received: "); } catch (IOException e) { message(e.toString()); } } } //Display a String message to the user. private void message(String msg) { //Display the message in the StringItem. messages.setText(messages.getText() + "\n" + msg); } //Signals the MIDlet to stop and enter the Pause state. public void pauseApp() { } //Signals the MIDlet to terminate and enter the Destroyed state. //Unconditional when set to true. The MIDlet must cleanup and release //all resources. //Otherwise, the MIDlet may throw a MIDletStateChangeException to //indicate it does not want to be destroyed at this time. public void destroyApp(boolean unconditional) { try { //Close the connection. mc.close(); } catch (IOException ioe) { System.out.println(ioe); } }

 

 

 

Please use plain text.
Administrator
MSohm
Posts: 11,465
Registered: 07-09-2008
My Carrier: Bell

Re: Receiving incoming connections when midlet is running

Can you elaborate on what is not working?  Is an exception thrown?  If so what is it?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.