for Android, by PurpleMAD
This plugin allows a user to save an image residing in the application folder or from a remote URL into the internal storage of the device. It also allows to set the image as a wallpaper which includes saving the image into the storage of the device.
User need to pass parameters as (imagePath, imageTitle, folderName, success, error) where
Wallpaper is compatible with Cordova Plugman and ready for the PhoneGap 3.0 CLI, here's how it works with the CLI:
$ phonegap local plugin add https://github.com/PurpleMADcanada/Wallpaper-PhoneGap-Plugin.git
or
$ cordova plugin add https://github.com/PurpleMADcanada/Wallpaper-PhoneGap-Plugin.git
don't forget to run this command afterwards:
$ cordova build
1. Add the following xml to your config.xml
:
<!-- for Android -->
<feature name="Wallpaper">
<param name="android-package" value="ca.purplemad.wallpaper.Wallpaper"/>
</feature>
2. Grab a copy of wallpaper.js, add it to your project and reference it in index.html
:
<script type="text/javascript" src="https://github.com/PurpleMADcanada/Wallpaper-PhoneGap-Plugin/raw/master/wallpaper.js"></script>
3. Download the source files for Android and copy them to your project.
Android: Copy Wallpaper.java
to platforms/android/src/ca/purplemad/wallpaper
(create the folders)
4. Set below permissions in AndroidManifest.xml file.
Using Wallpaper with PhoneGap Build requires these simple steps:
1. Add the following xml to your config.xml
to always use the latest version of this plugin:
<gap:plugin name="ca.purplemad.wallpaper" />
or to use this exact version:
<gap:plugin name="ca.purplemad.wallpaper" version="0.2.0" />
2. Reference the JavaScript code in your index.html
:
<!-- below <script src="https://github.com/PurpleMADcanada/Wallpaper-PhoneGap-Plugin/raw/master/phonegap.js"></script> -->
<script src="https://github.com/PurpleMADcanada/Wallpaper-PhoneGap-Plugin/raw/master/js/plugins/Wallpaper.js"></script>
Basic operations, you'll want to copy-paste this for testing purposes:
// prep some variables
var imagePath = "www/img/christmas.jpeg"; // Mention the complete path to your image. If it contains under multiple folder then mention the path from level "www" to the level your image contains with its name including its extension.
var imageTitle = "christmas"; // Set title of your choice.
var folderName = "PluginImages"; // Set folder Name of your choice.
var success = function() { alert("Success"); }; // Do something on success return.
var error = function(message) { alert("Oopsie! " + message); }; // Do something on error return.
// For setting wallpaper & saving image
wallpaper.setImage(imagePath, imageTitle, folderName, success, error);
// For saving image
wallpaper.saveImage(imagePath, imageTitle, folderName, success, error);