Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current wallpaper

I'm pretty new to Android programming so bear with me.

I was wondering if there was a method of retrieving the current wallpaper on an android device and saving it to a variable in your app's code.

Thanks

like image 634
moesef Avatar asked Mar 30 '12 08:03

moesef


3 Answers

final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
like image 111
Anand M Joseph Avatar answered Sep 19 '22 17:09

Anand M Joseph


This is the good way to do that:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
like image 32
Manitoba Avatar answered Sep 18 '22 17:09

Manitoba


This goes a step further and saves the file. You'll need exception handling of course and you'll need external write permission.

import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.app.WallpaperManager;

WallpaperManager wmInstance = WallpaperManager.getInstance(context);

wmInstance
    .getDrawable()
    .getBitmap()
    .compress(Bitmap.CompressFormat.PNG, 100,
        new FileOutputStream("/storage/emulated/0/output.png"))
like image 22
cong Avatar answered Sep 20 '22 17:09

cong