* BlackBerry PhoneGap Progress Report

Posted on December 6th, 2008 by Dave Johnson. Filed under phonegap.


BlackBerry PhoneGap
We had a PhoneGap sprint just over a week ago which was pretty successful for me and my BlackBerry ambitions as well as everyone else. Through that sprint and over the past week, despite some setbacks, I got the OS v4.5 installed on my phone and the simulator on my computer giving me access to a few new things but I was sad to find that a few other things were still sorely lacking that are pretty important for something like PhoneGap. Just so you know, OS v4.5 is the latest OS that will run on my Curve 8310 - 4.6 will run on the Bold, Pearl Flip and newer Curves while 4.7 works on the Storm. The two biggest gaffs by RIM are in the BlackBerry web browser for OS v4.5 where that the following rather important features are missing:

  1. You can’t pass function pointers to setTimeout.
  2. You can’t access DOM Nodes in any way shape or form (aside from form fields). So there is no getElementById or innerHTML on the resulting nodes. This make web application development a little bit difficult.
  3. There is no XMLHttpRequest object.
  4. While not really expected, there is no SQLite support
    anywhere on the phone as of yet, let alone the browser.

Anyhow, despite those setbacks on the v4.5 OS I did get the communication between the BlackBerry device and the web page all dialed now. Not only that but I have implemented the W3C geolocation API and am going to follow that same pattern for the other APIs. Check out the geolocation JavaScript interface as well as the platform specific implementation.

In the actual BlackBerry code there is lots of boiler plate stuff. The main hurdle was figuring what the best (or any) way to embed the browser in the application was and enable communication between JavaScript in the browser and the BlackBerry Java code. In the end I pretty much had to take the route of implementing the browser myself through the BrowserContentManager. This means that I have to implement lots of functionality, but it also means that I am in control of cookies and responsible for accepting them from JavaScript in the web page through the implementation of the browser fields RenderingApplication.eventOccurred method when the event type is EVENT_SET_HTTP_COOKIE and returning them to JavaScript by implementing the RenderingApplication.GetHTTPCookie method.

When the set cookie event occurs I parse out the cookies looking for one named bb_command and expect it to contain some JSON object (that is parsed with the J2ME port of a Java JSON lib) with a command property (like for opening maps or getting the GPS location) and some arguments (like points to plot on the map or how long to vibrate for). The case statement just looks like this:

switch (command)
{
  case 0:
    this._getLocation = true;
    this.startLocationUpdate();
    break;
  case 1:
    Invoke.invokeApplication(
      Invoke.APP_TYPE_MAPS,
      new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT,
      getLocationDocument(args))
    );
    break;
  case 2:
    Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA,
      new CameraArguments()
    );
    break;
  case 3:
    if (Alert.isVibrateSupported())
      Alert.startVibrate(getVibrateDuration(args));
    break;
  case 4:
    Invoke.invokeApplication(Invoke.APP_TYPE_PHONE,
      new PhoneArguments(PhoneArguments.ARG_CALL,
        getPhoneNumber(args)
      )
    );
    break;
  default:
}

where args is just a JSON string that the various methods like getPhoneNumber parse to get the args they want.

I will post some more specific code snippets like how to send text messages and so on very soon.

Tags: , , , , , , , ,



6 Responses to “BlackBerry PhoneGap Progress Report”

  1. BlackBerry PhoneGap Progress Report | bestwebhostingservices.com Says:

    [...] Excerpt from [...]

  2. Brian LeRoux Says:

    nice work dave — looks really good. we gotta get the js standardized across this implementations

  3. Dave Johnson Says:

    yes that has to happen asap. I was thinking of wrapping the current IPhone and Android JS with the new geo API as a start.

  4. Andre Charland Says:

    do you have to use the blackberry browser or could you embed Webkit or Fennec in there?

  5. Dave Johnson Says:

    I did some searches for webkit on Blackberry but have not found anything specifically as of yet. Of course I assume the Symbian S60 browser is Java based so it might be compilable for BlackBerry - that is something to look into. Haven’t tried Fennec. I wonder how big the download / install would have to be then if it included the entire browser.

  6. Symbian Blogger Says:

    I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.

Trackback URI | Comments RSS

Leave a Reply