18

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

moesef
  • 4,641
  • 16
  • 51
  • 68
  • None of the answers here helped, but the following answer worked for me: https://stackoverflow.com/a/53912364/647292. It uses the WallpaperManager.getWallpaperFile method. – Kioshiki Sep 08 '19 at 16:51

3 Answers3

41
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();

This solution is not valid for Android 13 https://issuetracker.google.com/issues/237124750?pli=1

Elias Fazel
  • 2,093
  • 16
  • 20
Anand M Joseph
  • 787
  • 7
  • 7
  • 11
    What if a Live wallpaper is set ? – S.D. Oct 12 '12 at 13:27
  • 2
    @S.D. In this case, I have no idea what will be returned, but you can call "getWallpaperInfo" in order to check if it's a live wallpaper : http://developer.android.com/reference/android/app/WallpaperManager.html#getWallpaperInfo() – android developer Jan 11 '15 at 09:43
  • @S.D. In this case, from what I see, the last set wallpaper will be returned. – Paul Apr 11 '15 at 12:14
  • Do you know whether this requires any permissions? – 今天春天 Nov 13 '15 at 19:06
  • As of android version 8.1, WallpaperManager.getDrawable() will require READ_EXTERNAL_STORAGE permission, unfortunately this is not talked about in the official docs. – Run Dec 27 '18 at 02:02
  • @QLocker exactly , but you will get SecurityException when you execute above snippet code and that SecurityException tell you to grant READ_EXTERNAL_STORAGE permission – Pritesh Vishwakarma Apr 12 '19 at 10:53
4

This is the good way to do that:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Manitoba
  • 8,522
  • 11
  • 60
  • 122
1

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"))
cong
  • 11
  • 1