Thursday, January 31, 2013


I've updated the GalleryPlugin to the Cordova 2.2.0 API but I've realized that I've never really talked about it. The GalleryPlugin is used when you need to add or remove a file from the Gallery or Music apps. Typical use cases include downloading an image from the internet and wanting it to show up in the Android Gallery app or conversely you delete a file and you don't want the dreaded black rectangle to be left in the Gallery app.

First lets take a look at what the gallery.js file. It's written using the cordova.define template but it still adds itself into window.plugins for those of you using the old style plugins:

Then will move on to the Java code. I've trimmed down code only to show the execute method for brevity.

In order to use this plugin you'll need to include the gallery.js in your HTML as a script tag:

and add a line to res/xml/config.xml to tell the JavaScript side where to find your Java class:

Now you should be able to add and remove images from the gallery. Here is some sample code to get you going:

1 comment:

ToRo said...

It works to store an image directly from a website? thank you.