Using WallpaperManager in Android to set wallpaper

ε祈祈猫儿з 提交于 2019-11-30 10:13:08

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!