Android: change desktop wallpaper programatically

Here is an instruction how to change desktop background on android device rogramatically by means of WallpaperManager. For simplicity the new wallpaper is taken from project resources.

private void setDesktopWallpaper() {
	try {
		WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
		wallpaperManager.setResource(R.drawable.my_wallpaper);
	} catch (IOException e) {
		SLog.e(TAG, "Error changing wallpaper: " + e.getMessage());
	}
}

To use another image (for example downloaded from the internet, you can use setBitmap method instead of setResource.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

Give Your feedback: