1

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;
}
RegisteR
  • 13
  • 3

1 Answers1

0

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)
}
Cuong Nguyen
  • 970
  • 6
  • 17
  • 1
    Thank you, one of the problems was solved, but the problem with the fact that on android 12 + wallpaperManager calls onDestroy() and onCreate() remained. Don't know how to solve this problem? – RegisteR Dec 09 '22 at 18:31