When calling WallpaperManager on Android 12, onDestroy is called and then onCreate immediately. And when you call WallpaperManager.setBitmap(hbitmap), the image on the home screen and lock changes, although on all devices except Android 12 it is installed only on the home screen, as it should be.
I've tried this
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
switch (ImageDialog.getWhere()) {
case 1:
try {
wallpaperManager.setBitmap(bitmap); // to the home screen
} catch (IOException e) {
e.printStackTrace();
}
break;
case 2:
try {
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK); // to the lock screen
} catch (IOException e) {
e.printStackTrace();
}
break;
case 3:
try {
wallpaperManager.setBitmap(bitmap); // to the home screen
} catch (IOException e) {
e.printStackTrace();
}
try {
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK); // to the lock screen
} catch (IOException e) {
e.printStackTrace();
}
break;
}
You should:
is Home Screen -> {
wallpaperManager?.setBitmap(
bitmap,
null,
true,
WallpaperManager.FLAG_SYSTEM
)
}
is Loock Screen -> {
wallpaperManager?.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK)
}
is Lock and Home Screen -> {
wallpaperManager?.setBitmap(bitmap)
}