To add assign an image as wallpaper, you can add an image stored in the project resources as Wallpaper or an image from an internet url :
Add as wallpaper an image stored in the project resources.
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.androide); //*Agrega imagen de recursos como Wallpaper
} catch (IOException e) {
e.printStackTrace();
}
Add an internet image as wallpaper.
You can also add an image from a url, and assign it as Wallpaper, in this second option you must perform the download process in a different thread from the main one to avoid the NetworkonMainThreadException error , to avoid this you must use a Thread, Asynctask, Handler , etc.
This is an example of a method which we call like this:
The way to change a phone's wallpaper programmatically is through the WallpaperManager class .
This class has several methods to change the wallpaper, get the current wallpaper, delete the wallpaper, etc.
In this other answer that I gave, I mentioned how to do it, change the home screen background and lock screen, resize according to the density of the screen, make it fixed, etc. See it from here .
The other way to change the wallpaper is based on an Intent. An example:
Here what it does is request a selector of the applications that match the action of the intent. Based on this, the user can choose with which application to change the wallpaper.
Add an image as Wallpaper on Android .
First you must register the permission:
To add assign an image as wallpaper, you can add an image stored in the project resources as Wallpaper or an image from an internet url :
Add as wallpaper an image stored in the project resources.
Add an internet image as wallpaper.
You can also add an image from a url, and assign it as Wallpaper, in this second option you must perform the download process in a different thread from the main one to avoid the NetworkonMainThreadException error , to avoid this you must use a Thread, Asynctask, Handler , etc.
This is an example of a method which we call like this:
This is the full method:
The way to change a phone's wallpaper programmatically is through the WallpaperManager class .
This class has several methods to change the wallpaper, get the current wallpaper, delete the wallpaper, etc.
In this other answer that I gave, I mentioned how to do it, change the home screen background and lock screen, resize according to the density of the screen, make it fixed, etc. See it from here .
The other way to change the wallpaper is based on an Intent. An example:
Here what it does is request a selector of the applications that match the action of the intent. Based on this, the user can choose with which application to change the wallpaper.
If you have any doubts, let me know.