Skip to Main Content
20 Recipes for Programming PhoneGap
book

20 Recipes for Programming PhoneGap

by Jamie Munro
March 2012
Intermediate to advanced content levelIntermediate to advanced
78 pages
1h 35m
English
O'Reilly Media, Inc.
Content preview from 20 Recipes for Programming PhoneGap

1.20. Extending PhoneGap with Plug-ins

Problem

You want to add additional functionality to your application for a specific device that the PhoneGap library currently doesn’t support.

Solution

Create a custom plug-in that is added to your application and invoke it with JavaScript via the window.plugin command.

Discussion

In this example, I am going to extend the PhoneGap library by creating and using an Android plug-in with the application. The goal of this plug-in will be to read an RSS feed and parse the XML into an array of JSONObject objects that will be outputted in the existing PhoneGap application. As I mentioned in the preface, I am developing on Windows using Eclipse, so the plug-in will be for the Android only, but implementing the plug-in is platform independent because it is done via JavaScript. In other words, if you were to download an iPhone plug-in, it could be implemented in a similar fashion.

To create a plug-in, a new Android Project must be created. In Eclipse, select File New Android Project. I am going to name the project XMLParser. For the Build Target, select the latest Android API. The “Application name” will be XMLParserPlugin. I’ve created the package as com.webistrate.phonegap.plugin.xmlparser (update as needed for your package). And finally, I unchecked Create Activity.

Once the new project is added, you also need to add the PhoneGap library to your project. Just like during the initial setup, you can copy the phonegap.jar file to a new libs directory and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

HTML5 Mobile Websites

HTML5 Mobile Websites

Matthew David
PhoneGap Build

PhoneGap Build

Bintu Harwani

Publisher Resources

ISBN: 9781449334383Supplemental ContentErrata