Wednesday, March 25, 2009

Push registry for sms in blackberry using midlet

I had been working around a requirement from my client and it was quite a nightmare. The codebase am working on is in j2me.
Now he wanted to port all the functionality of the code to the blackberry also.

Blackberry inherently does not executes jar/jad files. It first converts them in to cod file using its inbuilt converter RAPC and then executes them.

Now one of the functionality of my project was push registry.

The scenerio was as follows. When you start your midlet on any mobile it used to register a port for sms listening and sending . also it used to register it to AMS so that if application is not running and any sms comes on to that port then AMS can invoke my application and i will get that sms also. Till now everything was good. Everything was working fine.

I ported each and everything and it was not a big deal. But when the push registry scenerio came my world came down crashing on to me.

The code started issuing the following exception:

CLASSNOTFOUNDEXCEPTION: midlet not in current suite.

i started digging around on web for it and came to know that while registering the connection if the midlet name is not found then the following exception is thrown. Its been documented in the connector class. Also it needed the "MIDlet-1" parameter in the jad and manifest which contains the port to be registered, the name of the midlet and the filter.

So i thought may be that parameter is not passed , but when i checked in the executable it was there and was properly handled.

Now i dont know what to do.

Problem also lies in the concept of push registry . Blackberry does not have any concept called push registry, its been introduced only by j2me. So if i have to use it i have to write a midlet for blackberry. And in it , it was not working.

I searched on net all over and found so many ppl trying to work around this limitation of Blackberry but none of them have been able to.

So for whole three days i looked around and finally came to a conclusion that it cant be done in Blackberry.
We thought that we might have to shelve the blackberry from going into production as push registry was one of our key feature.

Then i got a idea . (Man am always full of ideas. )
Yesterday when i was looking for some more way arounds to solve this issue,(actually i was reading a book called "Vlad Taltos" by Steven Brust. Man am hooked onto fantasy reading , thanks to Ankit solanki. May Veera bless him. So when i finished the book ...) i thought of using a approach which no one have thought.

What if i dont ever close my application. That is when we exit from application we needed to close the port on which we were listening the sms. Now what push registry used to do was it used to keep the port status in its log. so when ever any sms came on to that port it will start the application , open and register that port again for application. But what if i never close that port?

Now issue was i have done something like this before. But i have seen that if we dont close the port and try to exit and then restart the app sometimes we will never get that port registered again.

So what i finally did was , instead of exiting the application send it into background.

what u say cheesy na :)

Blackberry has an option of sending an application in background and it can still recieve events.

so what i did was i imported the blackberry application api and sent the application in background when user wanted to exit it. Now a user thinks that app has exited but in reality its sitting in background waiting for the event . And when new sms comes on that port the application now checkes whether its in background or foreground. If foreground it does normal sms handling, but if its in background it brings the app in foreground , do a bit of initialisation and valla... we have push registry working here.

So this was my little adventure with blackberry and midlets.

May the winds of south have mercy on me.



8 comments:

ajpra23 said...

Were able to use push registry? or did u solve the problem.
'cause am facing the problem right now.There are a lot references with imply that push registry works in BB.I'm a little confused.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800429/How_To_-_Register_a_MIDlet_with_the_PushRegistry.html?nodeid=817112&vernum=0

R Ramana said...

Were you able to get sms trigger the application. I am also facing same issue and could not startup a application on receiving the sms. I tried on blackberry simulator 8300 model. Please mail me @ ramanurs@gmail.com if you have any success.

Thanks,
Ramana

Heart said...

Hi ,
I am also facing the same problem in blackberry.I have tried the requestbackground() and requestForeground() methods.But i can't get proper execution.Actually , i am using MIDlet class.
Please any one help me to solve this issue...here my mail id ithaya@gmail.com

Unknown said...

Hi all, I had a big stuck in this problem too. I am using the push registry in MIDlet on BlackBerry device. Please help me how to send my application in background. Thanks in advance.

Unknown said...

Hi all, I had a big stuck in this problem too. I am using the push registry in MIDlet on BlackBerry device. Please help me how to send my application in background. Thanks in advance.

Prabhakar aka Dex said...

Hi to all,

yes i was able to solve the issue. get in touch with me so that i can solve urs too.

Anonymous said...

Hi Prabhakar,

how do u solved this sending the Midlet application in Background on BlackBerry devices ???


Thanks,
Srini

Anonymous said...

Do you have any example code? Looking specifically how to "exit" to background. and how launch at startup. And how to listen for sms/push notifications.

Can you help me?
Greatly appreciated
Herman
gshmaritz at gmail.com

follow me