Using WallpaperManager in Android to set wallpaper

前端 未结 2 599
庸人自扰
庸人自扰 2021-01-01 04:32

Below are my codes, I want to use wallpaper manager to set as wallpaper. I\'m using Universal Image Loader, but i dont know how implement wallpaper manager. My setWall() is

相关标签:
2条回答
  • 2021-01-01 04:41

    You should convert your Drawable to a Bitmap and then use the setBitmap() function of wallpaper manager to set your desired wallpaper

    Convert Drawable to Bitmap

    private Bitmap getBitmapFromDrawable(Drawable d){
             Bitmap bitmap = 
                     ((BitmapDrawable) d).getBitmap();
             return bitmap;
    }
    

    Set as wallpaper

    public void setWall() { 
        WallpaperManager myWallpaperManager = 
             WallpaperManager.getInstance(getApplicationContext()); 
     try { 
        myWallpaperManager.setBitmap(getBitmapFromDrawable(R.drawable.app_icon); 
     } catch (IOException e) { 
        // TODO Auto-generated catch block e.printStackTrace(); 
     } 
    } 
    

    Hope this helps

    0 讨论(0)
  • 2021-01-01 04:45

    Instead of myWallpaperManager.setResource(0); Why didn't you use the myWallpapaerManager.setResource(R.drawable.yourimage)

    Have a look at Wallpapaer Manager example. Hope this helps you lot.

    0 讨论(0)
提交回复
热议问题