someone someone - 4 months ago 14
Android Question

android change wallpaper

I'm trying to change wallpaper on galaxy sIII (ICS os) device I'm using 1280x1440 jpeg image by this code:

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

....

Bitmap m = BitmapFactory.decodeByteArray(data, 0, data.length);
WallpaperManager.getInstance(this).setBitmap(m);


which is not working and following not working also:

Bitmap m = BitmapFactory.decodeResource(getResources(), R.drawable.data_img);
WallpaperManager.getInstance(this).setBitmap(m);


but when i use this:

WallpaperManager.getInstance(this).setResource(data_img);


it was work perfectly but my case is download some image data save it as bitmap then set it as wallpaper. so loading resources is not functional in my case.

any help, thanks in advance.

Answer

You can find the documentation here.

You have to use public void setStream (InputStream data) method:

InputStream ins = new URL("absolute/path/of/image").openStream();
WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setStream(ins);

OR, if you have image URI then use:

WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setResource(Uri.of.image);