0% found this document useful (0 votes)
45 views10 pages

Phonegap: Android: Training in Seattle, Wa Fil Maj Andrew Lunny

This document provides an overview of developing mobile applications for Android using PhoneGap. It discusses that Android has a fragmented landscape with many versions of the OS. PhoneGap allows accessing core Android features like sensors, GPS, and files from JavaScript. The document explains that PhoneGap works by loading a webview containing the application HTML/JS code, and bridging Java classes to JavaScript using an API. This allows accessing native features and plugins from JavaScript. It provides examples of setting up plugins to extend PhoneGap's capabilities on Android.

Uploaded by

Harsh Verma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views10 pages

Phonegap: Android: Training in Seattle, Wa Fil Maj Andrew Lunny

This document provides an overview of developing mobile applications for Android using PhoneGap. It discusses that Android has a fragmented landscape with many versions of the OS. PhoneGap allows accessing core Android features like sensors, GPS, and files from JavaScript. The document explains that PhoneGap works by loading a webview containing the application HTML/JS code, and bridging Java classes to JavaScript using an API. This allows accessing native features and plugins from JavaScript. It provides examples of setting up plugins to extend PhoneGap's capabilities on Android.

Uploaded by

Harsh Verma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PhoneGap: Android

Training in Seattle, WA Fil Maj Andrew Lunny

Platform Overview

Open source, woo! Gaining momentum, fast. Fastest growing mobile platform in the world. 60,000 devices shipping per day. Java. . Dalvik VM. . Many versions -> fragmentation

Android Fragmentation
We have Android 1.5, 1.6, 2.0, 2.0.1, 2.1, 2.1-update1 more coming! Whats worse: the APIs keep on changing. Makes it difficult for PhoneGap to be completely and truly crossplatform:
In 2.0 we got HTML 5 support in the browser, to a degree. 2.0.1 adds to the supported HTML 5 features. 2.1 adds even more Joe Bowser, main developer of PhoneGap Android, talks about this on his blog: http://blogs.nitobi.com/joe/2009/11/20/androidsplintering/

Android PhoneGap Features


If the phone can do it, PhoneGap apps can do it:
Sensors: accelerometer, vibrate, compass GPS! Network availability, offline storage Media File I/O

Complete list at http://wiki.phonegap.com/Roadmap

How It Works
The browser on Android delivers our app.
You can instantiate a new browser instance (the class is called WebView) from Java. You can get it to load assets from within your app -> this is where your HTML/CSS/JS comes in.

The WebView also has an API and allows us to do some cool things with it:
We can enable JavaScript and (Android 2.0+) native HTML 5 geolocation. Android 2.0+ also allows us to mess with localStorage.

How It Works, pt. 2


Android, similarly to iPhone, has a neat function in its API called addJavaScriptInterface. It is amazing magic. It binds arbitrary Java class instances that you work with on the native end to global JavaScript objects within a WebView (a.k.a. browser instance). Lets have a look:

The Crux of PhoneGap Android


gap = new PhoneGap(this, appView); geo = new GeoBroker(appView, this); accel = new AccelListener(this, appView); launcher = new CameraLauncher(appView, this); mContacts = new ContactManager(this, appView); fs = new FileUtils(appView); netMan = new NetworkManager(this, appView); mCompass = new CompassListener(this, appView); crypto = new CryptoHandler(appView); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(gap, "DroidGap"); appView.addJavascriptInterface(geo, "Geo"); appView.addJavascriptInterface(accel, "Accel"); appView.addJavascriptInterface(launcher, "GapCam"); appView.addJavascriptInterface(mContacts, "ContactHook"); appView.addJavascriptInterface(fs, "FileUtil"); appView.addJavascriptInterface(netMan, "NetworkManager"); appView.addJavascriptInterface(mCompass, "CompassHook"); appView.addJavascriptInterface(crypto, "GapCrypto");

Once we call addJavascriptInterface, we can then access the Java functions present in the Java class from the JavaScript object we just bound the class to!

PhoneGap Plug-ins for Android


Full article courtesy of Joe Bowser here: http://blogs.nitobi.com/joe/2009/12/17/introducingponygap-phonegap-plugins-for-android/ Although it IS doable, there is no standard approach for implementation. Fly by the seam of your pants. In general:
Write a Java class that encapsulates the functionality you are looking to provide to your application. In DroidGap.java, bind an instance of your class to some named JavaScript object using the addJavascriptInterface method. Add JavaScript wrappers, if necessary, to framework/assets directory. If your functionality needs callbacks, error handling and/or parameter parsing, you should probably create a JavaScript wrapper for it.

Application Deployment
Of all PhoneGap supported platforms, Android is by far the easiest to deal with when it comes to deployment and administration. No application reviews. nuf said. Cheap! Developer registration is $25 (compared to $100 for iPhone and $275+ for BlackBerry). Android Market is pretty rad, too, but needs to catch up to iPhone. 20,000 Android apps compared to 130,000+ iPhone apps.

Questions/Comments?

You might also like