2

I am trying to find Currently selected Live Wallpaper drawable , but this code every time returns me Default Live wallpaper Drawable, While my custom live wallpaper is set to my device.

WallpaperManager wallpaperManager wallpaperManager = WallpaperManager.getInstance( this);
Drawable wallpaperDrawable1 = wallpaperManager.getDrawable();
getWindow().setBackgroundDrawable(wallpaperDrawable1);

But Docs says it will return Currently selected live wallpaper, whats wrong with it,Is there any requirement to any permission in manifest.

Avijit
  • 3,834
  • 4
  • 33
  • 45

1 Answers1

0

Every live wallpaper will be found as a package in the device. So each live wallpaper package contains a drawable image, which we can get easily.

The method getWallpaperInfo() is used to get the information about the live wallpapers.

So getWallpaperInfo().loadThumbnail(PackageManager pm) method will do the trick for you.

The following code is used to get the drawable image of the live wallpaper:

    //Reference to the package manager instance
    PackageManager pm = getApplicationContext().getPackageManager();

    /*
     * Wallpaper info is not equal to null, that is if the live wallpaper
     * is set, then get the drawable image from the package for the 
     * live wallpaper
     */
    if (wallpaperManager.getWallpaperInfo() != null) {
         wallpaperDrawable = wallpaperManager
                .getWallpaperInfo().loadThumbnail(pm);
    } 

    /*
     * Else, if static wallpapers are set, then directly get the 
     * wallpaper image
     */
    else {
         wallpaperDrawable = wallpaperManager.getDrawable();
    }
Max Meijer
  • 1,530
  • 1
  • 14
  • 23
John
  • 9
  • 1
  • This does not actually work. For live wallpapers, it can (and often does) simply return a generic thumbnail representing any image. Tested with the google "Wallpapers" app. – alzee Nov 26 '16 at 14:40
  • loadThumbnail might return null though getWallpaperInfo() isn't null. So whoever gonna use this code, make sure to check the returned drawable against null before using it to avoid NullPointerException. – Ashraf Alshahawy Nov 10 '20 at 23:42