This simple plugin gives you the ability of setting the systems wallpaper, either by using an image you brought with the application in its www-directory or by using a Base64-encoded string of an image. This lets you choose the image after the installation of the application and even change it afterwards, you just have to pass over a new Base64 encoded image.
cordova plugin add https://github.com/ragcsalo/cordova-plugin-wallpaper.git
Saves the current Homescreen wallpaper as a Base64 string to Shared Preferences:
window.plugins.wallpaper.saveWallpaper();
cordova plugin add https://github.com/ragcsalo/SharedPreferences.git
sharedpreferences.getSharedPreferences("WallpaperPref", "MODE_PRIVATE", function() {
sharedpreferences.getString("original_wallpaper", function(wp64){
window.plugins.wallpaper.setImageBase64(wp64);
}, function(err) {console.log('ERROR: '+err);});
}, function(err) {console.log('ERROR: '+err);});
Sets image under given path as Homescreen or Lockscreen background image:
window.plugins.wallpaper.setImage(string [image path], string [type]);
window.plugins.wallpaper.setImage('img/mybackground.jpg'); // set Homescreen wallpaper
window.plugins.wallpaper.setImage('img/mybackground.jpg','lock'); // set Lockscreen wallpaper
Sets image from URL as background image:
window.plugins.wallpaper.setImageHttp(string [image URL], string [type]);
window.plugins.wallpaper.setImageHttp('https://example.com/image.jpg'); // set Homescreen wallpaper
window.plugins.wallpaper.setImageHttp('https://example.com/image.jpg','lock'); // set Lockscreen wallpaper
Sets image contained in Base64 string as background image:
window.plugins.wallpaper.setImageBase64(string [Base64 string], string [type]);
window.plugins.wallpaper.setImageBase64(base64); // set Homescreen wallpaper
window.plugins.wallpaper.setImageBase64(base64,'lock'); // set Lockscreen wallpaper
Every function provides optional callbacks. The callback provides an error parameter in case there is an error. If there is no error, everything went well:
window.plugins.wallpaper.setImage('path/to/image.png', function(error) {
if (error) {
console.error(error);
}
else {
console.log('Success setting wallpaper.');
}
});
The plugin is licensed under Apache 2.0. The Apache 2.0 license can be found in the root directory of this project as well as the projects NOTICE.