View
 

How to Install a PhoneGap Plugin for Android

Page history last edited by Dave Johnson 9 months, 3 weeks ago

There are two parts to any PhoneGap plugin, native code and JavaScript code. There could also be third party native libraries and other web assets like HTML, CSS and images.

 

On Android, the plugin Java source code needs to be included in your PhoneGap Android project either in source form or as a JAR library.

 

In addition, the JavaScript for the plugin needs to be added to the ./assets/www/* folder of your PhoneGap Android project and linked in your HTML source code.

 

The final thing that needs to be done is an additional element needs to be added to the ./res/xml/plugins.xml file. The plugins.xml file describes what plugins are allowed to be called from JavaScript and maps a friendly plugin name like "BatteryLevelPlugin" to the class name that implements the plugin like "com.example.BatteryLevelPlugin". The plugins.xm file should look like this:

 

<plugins>
...
     <plugin name="BatteryLevelPlugin" value="com.example.BatteryLevelPlugin" />
...
</plugins>

 

The developer of the plugin should document what the name and value are that need to be added to the plugins.xml file. If that is not clear then you figure out the name used since it appears in calls to PhoneGap.exec(success, failure, "BatteryLevelPlugin", "..."); and you can figure out the fully qualified Java class if you have access to the plugin source code.