April 20, 2009
When developing mobile software at Future Platforms, one of our key objectives is always to keep the application as compact as possible. This is important for a couple of reasons: firstly, it minimises cost to the user when downloading the application over the air, and secondly, some handsets impose an upper limit on the size of application they accept.
The competition rules state that the total app size must be 5120 bytes or less. For Java ME, this consists of a compressed, obfuscated JAR file.
My idea was one which I had wanted to do for a while: an application which lets you easily communicate your location to a friend using your phone’s GPS. Myself and Thom have discussed on a couple of occasions how useful it would be to just zap your location to somebody when arranging a rendez-vous, and let them view it on a map: far better than providing lengthy directions over the phone. I was sure this could be achieved in 5K.
I ended up with a reasonably full-featured application. We make use of the Location API to access the handset’s GPS and landmarks store, the PIM API to access the contacts list, and the SMS API to access messaging functionality. Additionally, we use the Push registry to automatically start the application when a relevant SMS is received.
Once the location is saved as a landmark, it is easy to use the phone’s mapping software to view the location on a map. We even provide the facility to attach a short text message. If the location is sent to a handset which doesn’t have the application installed, it is usually possible to view the location and message as a normal SMS (depending on the handset).
We are more used to making applications in the 300K region! So creating one with a 5K size constraint was good discipline. The application consists of only two classes, with work being done in as few methods as possible, and variables being reused for several different purposes. With some careful refactoring and a bit of experimentation, the size was brought down to exactly 5120 bytes. This even includes code allowing the application to fail gracefully when installed on a handset without GPS.
The application should work on any handset with GPS available, however it has only been tested on Nokia Series 60 devices (N78, N82, N95, 6220 etc).
A few extra bits I would have liked to include are animation on the “Finding location” and “Sending message” screens, and the facility to manually enter a number to send the location to.
It was interesting and instructive to see how it’s possible to create a fairly complete and useful application in a small amount of code.
To try Where Are You on your phone, point your mobile browser to http://tinyurl.com/c4o4op.