I finally got around to writing an app I can run on my Blackberry. After investigating, I decided to make a MIDlet, rather than a native Blackberry app. This way, it will run on just about any java mobile platform. Plus, on first glance I thought the user interface API was clearer. In fact, after reading just one or two articles, I felt like I could make a simple MIDlet app with no problem.
The goal was simple: use the jaiku api to post presence updates to my jaiku stream. I know there are utilities like IMified that allow you to make updates over AIM or gtalk. To preserve my battery life, though, I often keep my Blackberry’s AIM/jabber client offline. I really just wanted a simple app to make the JSON api call. There is the moblet in 24hrs project, but it started on April 14th and isn’t done yet… that’s a loooong 24 hours! I got tired of waiting.
Programming Paradise
I had already written a command-line app to post to jaiku in haskell, so I knew how to make the API call already. All I needed to do was define a screen with a text field, and a ‘post’ command that would cause the HTTP POST. Initially, I just hardcoded the username and personal key information into the app. In the next version (next weekend?) I’ll use the mobile RMS api to store those settings in non-volatile memory. At that point, I’ll put the code up here so people can use it if they want.
So, I wrote the utility in probably half an hour, just starting with one of the many ‘hello world’ MIDlets you can find online. I downloaded the newest version of the Blackberry JDE (java development environment) to compile it with. Blackberrys run ‘java’ but they don’t use a normal JVM. This means you don’t move JAR files to your phone, but rather transcoded COD files. So, blackberry-specific tools are needed even when you are careful to only use standard java classes.
Learning how to make a mobile java-based app turned out to be not only easy, but fun. I was happy to see that the way they try to map commands to phone buttons in a phone-agnostic way matched up almost exactly with the way I had suggested doing this on another mobile platform. So, I felt very “in-tune” with the MIDlet way of doing things. I am always surprised by how much code you have to write in java to do anything, though. Haskell and OCaml have spoiled me with their brevity, I think!
Trouble In Paradise
I was a bit annoyed that the JDE is a windows-only app. I do almost all my coding on macs. Oh well… I do have an XP laptop, so it wasn’t a huge deal. In the JDE, my code compiled and ran perfectly in their BB 8700 emulator. So, I moved the package onto my actual phone. You can imagine my surprise when the phone immediately went into an unending series of restarts. It never got past the blank white screen, always failing after a couple seconds and starting over. Worse, removing the battery and reinserting it didn’t help. The ‘java_loader’ application that can be used to wipe the phone’s memory could not connect to the device, since it never started up.
After a lot of searching, I found a way to reinstall the OS while the battery is not in the device. Thankfully, I had backed up all my data just prior to this adventure. But, when I re-loaded the app, the same problem arose, and I had to reinstall the OS again. This takes like 20 minutes, so I was not happy.
Problem Solved
After a lot of searching, I finally found the suggestion that the JDE version 4.1 was appropriate for 8700 phones, while the newest version (4.2) was not compatible. Apparently, the JDE versions are tied to the phone versions, even though I couldn’t find anything in the release notes about this. Not to mention, the JDE 4.2 comes with an 8700 simulator (and older models as well)! I was extremely skeptical that switching JDEs would do the trick. But, I tried it and sure enough, my phone was happy.
I guess RIM has never heard of cross-compiling. I can imagine that it must be terribly confusing to host an app for many blackberry models, if they all must be compiled with different JDE versions. It would be much better if the phone itself would transcode any JAR files you give it, I think…
Success!
I didn’t think to grab an emulator screenshot from my XP laptop, and I’m writing this from one of my macs. But, you can see the first successful post to jaiku!