PurpleMADcanada / Wallpaper-PhoneGap-Plugin

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.
Other
18 stars 13 forks source link

Usage for cordova 3.3 #2

Open redrabbit85 opened 10 years ago

redrabbit85 commented 10 years ago

Edit Wallpaper.js

cordova.define("ca.purplemad.wallpaper.wallpaper", function(require, wallpaper, module) { var wallpaper = { setImage: function(imagePath, imageTitle, folderName, successCallback, errorCallback) { cordova.exec( successCallback, // success callback function errorCallback, // error callback function 'Wallpaper', // mapped to our native Java class called "Wallpaper" 'setwallpaper', // with this action name [{ // and this array of custom arguments to create our entry "imagePath": imagePath, "imageTitle": imageTitle, "folderName": folderName }] );

},
saveImage: function(imagePath, imageTitle, folderName, successCallback, errorCallback) {
    cordova.exec(
        successCallback,    // success callback function
        errorCallback,      // error callback function
        'Wallpaper',        // mapped to our native Java class called "Wallpaper"
        'savewallpaper',    // with this action name
        [{                  // and this array of custom arguments to create our entry
            "imagePath": imagePath,
            "imageTitle": imageTitle,
            "folderName": folderName
        }]
    );

}

}; module.exports = new wallpaper(); });

Basic operations, you'll want to copy-paste this for testing purposes:

document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { // prep some variables

// prep some variables var imagePath = "http://demos.jquerymobile.com/1.4.0/_assets/img/jquery-logo.png"; // 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 = "gaga"; // Set title of your choice. var folderName = "img"; // 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);
};

smorstabilini commented 10 years ago

thanks redrabbit85. without your fix the success callback was not called.

smorstabilini commented 10 years ago

Actually, I had to remove redrabbit85' fix. I installed the notification plugin and the installation process added the same lines added by redrabbit85. My app stopped to work because of the duplicated code. To fix this problem I had to remove the wallpaper-plugin and reinstall it, this time without applying any change. I don't know which plugin is broken, but I hope this note might save time to someone else.

PurpleMADcanada commented 10 years ago

Hello smorstabilini. We are very sorry for replying so late. We are happy that your issue is being solved. Kudos :-) Thanks, PurpleMAD