Skip to content

fbsanches/cordova-plugin-wallpaper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Title Description
Set Wallpaper
Set an image from a Cordova Android app as Homescreen or Lockscreen wallpaper.

cordova-plugin-wallpaper

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.

Table of Contents

  1. Installation
  2. Usage
  3. License
  4. Supported Platforms

Installation

cordova plugin add https://github.com/ragcsalo/cordova-plugin-wallpaper.git

Usage

Function(s)

saveWallpaper

Saves the current Homescreen wallpaper as a Base64 string to Shared Preferences:

window.plugins.wallpaper.saveWallpaper();
Notes
  • Homescreen wallpaper is stored as a Base64 string
  • saved to Shared Preferences named "WallpaperPref", in a String named "original_wallpaper"
  • if you want to restore the saved wallpaper, you can use the SharedPreferences plugin to retrieve it:
cordova plugin add https://github.com/ragcsalo/SharedPreferences.git
Example: retrieve and restore the saved wallpaper
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);});

setImage

Sets image under given path as Homescreen or Lockscreen background image:

window.plugins.wallpaper.setImage(string [image path], string [type]);
Notes
  • path must not start with bar
  • path has not to start with backslash
  • add second parameter 'lock' if you want to set the Lockscreen wallpaper
Example
window.plugins.wallpaper.setImage('img/mybackground.jpg'); // set Homescreen wallpaper
window.plugins.wallpaper.setImage('img/mybackground.jpg','lock'); // set Lockscreen wallpaper

setImageHttp

Sets image from URL as background image:

window.plugins.wallpaper.setImageHttp(string [image URL], string [type]);
Example
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

setImageBase64

Sets image contained in Base64 string as background image:

window.plugins.wallpaper.setImageBase64(string [Base64 string], string [type]);
Example
window.plugins.wallpaper.setImageBase64(base64); // set Homescreen wallpaper
window.plugins.wallpaper.setImageBase64(base64,'lock'); // set Lockscreen wallpaper

Callbacks

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.');
  }
});

License

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.

Supported Platforms

  • Android

About

Cordova Set Wallpaper Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published