PhoneGap Plugins Joe Bowser joe.bowser@nitobi

tomatogilamonsterInternet and Web Development

Jun 24, 2012 (4 years and 4 months ago)


PhoneGap Plugins
Joe Bowser

About PhoneGap

PhoneGap is an HTML5 app platform that
allows you to author native applications with
web technologies and get access to APIs and
app stores

Exists on iPhone, Android, Blackberry
WebWorks, Windows Mobile 7, Symbian,
WebOS and Samsung bada

Allows developers to get the majority of their
app developed quickly

PhoneGap Application Examples

Android Examples:

National Film Board of
(NFB Films)


Logitech Squeezebox

Registered Nurses of
Ontario (RNAO)

Vimeo Mobile (by

NFB Application (Honeycomb)

Why plugins exist

When working on projects (including the NFB
project), we needed to extend PhoneGap

The NFB Application has these Native Features

Video Player

NFB Desktop Widget

Native Menus

We had to extend PhoneGap with native code
to step in where the browser stopped working

Do I need to write a plugin?

PhoneGap Android currently supports:

Geolocation (HTML5 replacement)






Network Status/Reachability


Do I need to write a plugin (cont)?


File Transfer



These features are themselves plugins and will
become more modular

If you need features, other than this, or if the
web performance would be too slow, you need
a plugin

PhoneGap Plugins?

There is a phonegap-plugins repository with
various plugins

Plugins are written in the native language of the
platform (iOS plugins are in Objective-C,
Android plugins are written in Java)

Plugins consist of a native library or source file,
and a Javascript interface file

Plugins are the preferred way of extending
PhoneGap without running into errors

Examples of Plugins

Found at





Barcode Scanner

Google Analytics

Video Player

Installing a Plugin on Android

Create a PhoneGap Project

Copy the Java files to where their package
would be

Edit the resource file res/xml/plugins.xml

Build the Application

Writing an Android Plugin

Android plugins are written in Java

Some people are fine with this and use vim to
write Java

I am not one of these people. I still use Eclipse
to do Java Development (I write all my other
code in vim)

We're going to work on a plugin LIVE!

The Live Demo
Live Coding will be involved

Summary of the Demo

Get PhoneGap-Android Source

Create a project to develop the plugin

Create a class to extend the Plugin object

Implement native methods in that package

Write a JS layer to use PhoneGap.exec()


PhoneGap plugins are useful when you need
the following

Native Functionality that isn't in any W3C

Optimized APIs for when Javascript today just isn't
the right choice (Cryptography, for example)

Integrating 3
Party APIs for Android to add a more
smooth user experience

For more information

PhoneGap website:

IRC: #phonegap on

Twitter: @phonegap

Code Examples from this presentation: