Archive for August, 2010

* Mobile Geolocation Implementations

Posted on August 19th, 2010 by Dave Johnson. Filed under Uncategorized, phonegap.


Today I found some time to take a look at the various mobile implementations of geolocation.

Below is a table showing the properties that the geolocation API uses on the various platforms. The W3C geolocation API for browsers specifies a PositionOptions interface that requires a maximum age, timeout and accuracy. Below that row is all of the mobile platforms that we are interested in for PhoneGap and the properties that they support in their native implementations. Some of them support a distance filter that will cause the device to only return geolocation positions if the location has changed by more than that distance while others also support an explicit interval for watching for location changes (note that on Android that interval is only a hint to let the device know how much power to use in getting a location - the position may be reported at an interval either shorter or longer than the specified interval).

I am probably going to be adding these two additional arguments to the PhoneGap PositionOptions and they can be used on platforms that support them.

Max age Timeout Accuracy Distance Interval
W3C X X X
BlackBerry maxAge timeout - - interval
iPhone - - desiredAccuracy distanceFilter -
Android - - - minDistance minTime
webOS maximumAge responseTime accuracy - -
WRT updateMaxAge updateTimeout - - updateInterval
Winphone - - DesiredAccuracy MovementThreshold

Image from cloneofsnake

Tags: , , , .



* PhoneGap Native Bridge

Posted on August 13th, 2010 by Dave Johnson. Filed under JavaScript, mobile, phonegap.


The “native bridge” is the secret sauce of PhoneGap and is what allows JavaScript in an embedded browser talk to native code and vice-versa.

On every platform we do this differently depending on what features that native browser has. Here is the list of platforms and how we do it.

iPhone: To communicate from JavaScript to native we call window.location = “gap://Class.method/args” and then intercept the url in native code and parse our the parameters. The class / method is then dynamically loaded / called. To call JavaScript from native we use UIWebView.stringByEvaluatingJavaScriptFromString.

Android: Communication from JavaScript to native takes advantage of the native WebView.addJavascriptInterface to expose Java objects directly to JavaScript. To call JavaScript from native we currently use WebView.loadUrl(”javascript:…”) but that has some problems so we are soon moving over to polling a Java message queue calling a local HTTP server via a long-lived XHR connection.

BlackBerry 4.x: document.cookie is the only way to talk between JavaScript and native. JavaScript sets the cookie for native to read and JavaScript polls the cookie for messages from native. Fucking elegant!

BlackBerry Widgets: Astoundingly the new BlackBerry Widgets SDK is pretty damn nice. You can expose Java objects to JavaScript with ScriptEngine.addExtension and you can call JavaScript from native with ScriptEngine.executeScript. The context for the JavaScript execution can even be specified. Seriously great work there.

QT: This one is not quite ready but it will use the QWebFrame.addToJavaScriptWindowObject to expose native objects to JavaScript and will likely use polling of those exposed native objects to get data back into JavaScript - much like the Android approach

Windows Phone 7: There is something called window.external.Notify in the browser (mapped to a native object through the ScriptNotify event) on Windows Phone 7 that we use to send messages into native code. Going the other way there is WebBrowser.InvokeScript.

webOS, WRT: The platforms that are just JavaScript don’t have any native code. Well, we might look into the native side of webOS one day but no time soon.

In an attempt to clean up the PhoneGap JavaScript API a bit, I have isolated all the places that we communicate from JavaScript to native code and put it into a single PhoneGap class. I am now in the process of converting over all the JavaScript to use this new PhoneGap interface and then most of the PhoneGap JavaScript will be completely cross platform. Any call to native code now has to go through the PhoneGap.exec() JavaScript method. The new code is up on Github and with any luck all the platforms will be using it soon!

Image by hb2

Tags: , , .



* PhoneGap and BlackBerry OS 6

Posted on August 5th, 2010 by Dave Johnson. Filed under Uncategorized.


RIM OS 6 for BlackBerry smartphones is being released very soon on the new BlackBerry Torch 9800.

It looks like a pretty nice upgrade from OS 5, most notably including a WebKit based browser. This should be a *huge* improvement for PhoneGap on BlackBerry.

The bad news is that OS 6 will not work on a lot of the older hardware. OS 6 will run on the following:

  • Storm 3 (as yet unreleased)
  • Bold 9700
  • Bold 9650
  • Perl 9100

Notable devices missing from that list are the original Bold 9000 and the Storm 1 and 2. Those will be stuck on OS 5.

The kicker here is that anecdotally, and based on AdMob stats from April 2010, the most widely used RIM devices (remember AdMob stats represent devices that ads are being served to) are from the BlackBerry Curve line 8300 and 8520 in the US and UK respectively.

The tentative plan for PhoneGap on BlackBerry is likely going to be a “final” release for BlackBerry 4.6 / 4.7 tagged on Github (sometime in the near future) and then shifting focus to BlackBerry Widgets on OS 5 and 6.

.