Skip to content

Instantly share code, notes, and snippets.

@m00sey
Created July 1, 2011 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m00sey/1059312 to your computer and use it in GitHub Desktop.
Save m00sey/1059312 to your computer and use it in GitHub Desktop.
Loading Plugins from AndroidManifest

Loading plugins from the AndroidManifest.xml As an alternative to registering plugins through JavaScript plugins can now be loaded via the AndroidManifest, using the meta-data element.

A demo can be found at https://github.com/m00sey/Toasty (you'll need to update the jar to 9.6.1)

Registering a plugin

Plugin names are prefixed with plugin. this is so the keys can be identified when loading the meta data. The value is the fully qualified name.

This is the most 'consumer of 3rd party phonegap plugin' friendly - however if we looking to extract all 'plugins' (accelerometer/camera) I would suggest the 2nd alternative mentioned further down (arrays.xml).

JavaScript initialization

if (!PhoneGap.hasResource("tp")) { PhoneGap.addResource("tp");

var ToastPlugin = function() { };

//awesome JS ninjary

PhoneGap.addConstructor(function() {
if (typeof navigator.tp === "undefined") { navigator.tp = new ToastPlugin(); } }); } Alternatives Supply a value attribute to indicate the meta-data represents a plugin

The name of the plugin would be derived from the last portion of the qualified name.

Use arrays.xml

com.chariotsolutions.toast.plugin.ToastPlugin I feel this is the correct 'Android' way to do it, but as someone consuming the plugin, it is still painful. Check values/arrays.xml exists, if not, create it. Add some unfamiliar arbitrary xml format with my plugin. Add an entry to AndroidManifest.xml as well - feels crap.

On the flip side, this would lend itself nicely to being a method to do 'selective builds' (only including the pieces of phonegap you want)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment