O'Reilly logo

PhoneGap by Andrew Lunny

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Android and BlackBerry

Android first—get your Android project set up through Droidgap as usual. You want to have a bare PhoneGap Android project ready, with the contents of the www directory from our iPhone example.

  1. We will need to make one small change to our JavaScript, in plugins/battery.js. As mentioned above, Objective-C has all sorts of metaprogramming and reflective goodness to ensure we don't need to explicitly register our plugins. Unfortunately, Android, a Java-based platform, has no such niceties.

    We need to edit our addConstructor call appropriately:

    PhoneGap.addConstructor(function() { // add plugin to window.plugins if (!window.plugins) window.plugins = {}; window.plugins.battery = new Battery(); // register plugin ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required