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
Developer
dinu_hasith
Posts: 15
Registered: ‎10-23-2008
My Device: Not Specified

PushRegistry support for UiApplication

hi guys,

   does UiApplications support pushRegistry? because I hve a UiApplication that needs to recieve a SMS on a port registered to it. I tried to implement it using code samples given in the articles but they didn't work. I couldnt find any PushRegistry examples for UiApplications.

 

Is there any other way to implement pushregistry functionality for UiApplications?

 

Thanks,

Dinu

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: PushRegistry support for UiApplication

The PushRegistry APIs are designed for use with MIDlets, not BlackBerry CLDC applications.  You can find sample code on how to listen for incoming SMS messages here:

 

What is - Different ways to listen for SMS messages
Article Number: DB-00579

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

 

What problems are you having with your current implementation?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
dinu_hasith
Posts: 15
Registered: ‎10-23-2008
My Device: Not Specified

Re: PushRegistry support for UiApplication

Hi Mark,

here's an overview of what I need to do:

 

1. listen to an incomming SMS on port 50001 (sms://:50001)

2. when a message is recieved start the app and push a screen to display the recieved message.

 

I tried the alternate entry point approach. I didnt get any errors when running. I was asked to reboot the device(8300) after installing the app.  

I am able to start the gui using the ribbon icon. but i dont know how to start the app when a message is recieved and push a screen.

 

here's my UiApplication class

 

public class App extends UiApplication { ViewMessage mMainMenu; //MessageThread myThread; App() { mMainMenu = ViewMessage.createMainMenuInstance(); pushScreen(new HelloWorldScreen()); } public static void main(String[] args) { if(args != null && args.length > 0 && args[0].equals("gui")) { App myApp = new App(); myApp.enterEventDispatcher(); } else { MessageThread myThread = new MessageThread(); if(myThread == null) { //impossible to create thread... so exit System.exit(-1); } else { try { Thread.sleep(2000); myThread.start(); } catch(Throwable ie) { } } } } }

 

 

here's my background thread to listen to incomming SMSs.

 

class MessageThread extends Thread { String url = "sms://:50001"; MessageConnection currentMessageConnection; private boolean _stop = false; MessageThread() { try { currentMessageConnection = (MessageConnection) Connector.open(url); }catch(Exception e) { System.out.println(e.toString()); } } public synchronized void stop() { _stop = true; try { currentMessageConnection.close(); // Close the connection so the thread returns. } catch (Exception e) { System.err.println(e.toString()); } } public void run() { while(true) { try { if ( _stop ) { return; } TextMessage txtMsg = (TextMessage)currentMessageConnection.receive(); String data = txtMsg.getPayloadText(); String address = txtMsg.getAddress(); address = address.substring(6); PixMeMessage pixMeMessage = (new PixMeMessage()).insert(data, address); //start the gui part and push a screen to display the message. }catch(Exception e) { System.out.println(e.toString()); try { //Thread.currentThread.wait(1000); }catch(Exception ex) { System.out.println(ex.toString()); } } } } }

 

 

my MainScreen class to view the message.

 

public class ViewMessage extends MainScreen { BasicEditField fileId = new BasicEditField("fileId:", ""); BasicEditField msg = new BasicEditField("msg:",""); BasicEditField address = new BasicEditField("address:",""); public static final long RTSID_MY_APP = 0x33abf322367f9019L; public ViewMessage(PixMeMessage pix) { fileId.setText(pix.pictureID); msg.setText(pix.text); address.setText(pix.address); add(fileId); add(msg); add(address); } public ViewMessage() { fileId.setText("hello"); add(fileId); } public static ViewMessage createMainMenuInstance() { //Ensure this is a singleton instance. try { //Open the RuntimeStore. RuntimeStore store = RuntimeStore.getRuntimeStore(); //Obtain the reference of MainMenu. Object obj = store.get(RTSID_MY_APP); if (obj == null) { //Store a reference to this instance in the RuntimeStore. store.put(RTSID_MY_APP, new ViewMessage()); return (ViewMessage)store.get(RTSID_MY_APP); } else { return (ViewMessage)obj; } } catch(ControlledAccessException e) { System.err.println(e.toString()); return null; } catch(Throwable e) { e.printStackTrace(); return null; } } public static ViewMessage getMainMenuInstance() { //Ensure this is a singleton instance. try { //Open the RuntimeStore. RuntimeStore store = RuntimeStore.getRuntimeStore(); //Obtain the reference of MainMenu. Object obj = store.get(RTSID_MY_APP); if (obj == null) { return null; } else { return (ViewMessage)obj; } } catch(ControlledAccessException e) { System.err.println(e.toString()); return null; } catch(Throwable e) { e.printStackTrace(); return null; } } }

 

It would be great if you can point me in the right direction since I'm at a loss as to how to implement this functionality.

 

thanks

Dinu

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: PushRegistry support for UiApplication

You wouldn't start the application when the message arrives.  Instead, the entry point of the application that is listening for incoming connections should auto-run on startup (you can set this in the project properties in the BlackBerry JDE).

 

Once a message arrives, your application can call UiApplication.requestForeground to bring itself to the foreground and then display your GUI.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Ashik
Posts: 75
Registered: ‎04-07-2009
My Device: Not Specified

Re: PushRegistry support for UiApplication

Hi! I saw the discussion. I have also same problem. According ur suggestion (set auto_run_on _startup option be true). Is that application fuctionality will work even when the applicaiton is not in running state.

pls, suggest me---

Thanks in advance----

New Developer
Ashik
Posts: 75
Registered: ‎04-07-2009
My Device: Not Specified

Re: PushRegistry support for UiApplication

Pls, reply -----