public void changeWallpaper(String path) {
FileInputStream is;
BufferedInputStream bis;
WallpaperManager wallpaperManager;
Drawable wallpaperDrawable;
File sdcard = Environment.getExternalStorageDirectory();
try {
is = new FileInputStream(new File(path));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createBitmap(bitmap);
wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
Above code works for me And do not forgot to add
<uses-permission android:name="android.permission.SET_WALLPAPER" />
in AndroidManifest.xml file
You can convert your drawables into bitmap also
BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_name);