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.



Monday, March 23, 2009

Bulding projects using polish and porting.

For last few months i have been working on a project which has a lot of going in and around.
first of all its a mobile project. Second it targets all the leading mobile devices available around.

The language of code is so called j2me. For the porting purpose j2me polish has been used.

Now it was my first interaction with polish and for first few days or i should say months i was amazed at how polish accomplishes such a tedious task.

Being in to mobile industry for quite some time i know how tedious and complex is the task of supporting n number of devices which have all together different property set.

The properties are not just the screen size or the api sets , but also the underlying OS capabilities, changes in the same OS as there are always some feature packs available. Key pad mapping, UI capabilities mapping, Use of restricted apis and blab blah blah.

It was always a nightmare for me when i had to port any of my application onto all target devices.
But polish seems to do it quite painlessly.

So i thought why not give polish a close look and see how it does that.

what i found out was quite straight and simple.
Polish with the help of ant takes control of complete building process of any j2me application.

The polish people have written their own routines and code fragments which overrides the default building process. Along with that they have also used the brute force.

What i mean by brute force is they have indexed all the important and not so important capabilities and features of mobile and have made a standard around it. Now whenever you are building a build for any device, its capabilities are hand written in one of the files given by polish people.

this file is called devices.xml. This xml has got indexed features of n number of mobile devices and its ever growing. We can add our own blocks also in it.

Now this all seems to good , but at the end what i found out was it all is on good faith. As its open to changes by anyone, anybody can play around with it. Its very easy to change the name of any device or its feature.

Also i found porting to different devices buggy.

The code am working on has to work on blackberry also. Now during the build process itself the polish issues warning like error in jdptask and utiltask. Even if you build its demo project for blackberry you get the same issue. The web is full of issues faced by developers while porting on different devices.

Some how i fixed the jdp error in the polish jar and when i run the blackberry cod on the device it gives refrence member out of range error. Now its something which cannot be resolved by a developer. am still stuck on it and finally have decided to re write the whole code in blackberry ide itself and build blackberry native code.

So for small portings and portings on normal devices polish is good, but for other devices and for complex projects play with it at your own risk. :)

follow me