Android: change wallpaper for drawing

I use this code to change android home wallpaper.

WallpaperManager wm = WallpaperManager.getInstance(this);
wm.setBitmap(myBitmap);

I would like to set the background to drawable. Is it possible?

+3
source share
1 answer

First you need to convert Drawable to Bitmap. How to do this, I found here . You will need to use the BitmapFactory class, in particular the decodeResource () method.

Just pass the resources and the resource identifier as parameters, for example:

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
wm.setBitmap(bmp);
+5
source

Source: https://habr.com/ru/post/1770820/


All Articles