How to set android lock screen image

robintw picture robintw · Apr 16, 2010 · Viewed 28.4k times · Source

I'm just getting started with android programming, and want to see if there is a way to programmatically set the lock screen image. I've found various ways of setting the wallpaper in the API, but I can't seem to find the equivalent ways of setting the lock screen image.

I've seen various posts saying that customising the lock screen by adding widgets or bits of applications is not possible, but surely there must be a way to set the image programmatically?

Cheers,

Robin

Answer

mikepenz picture mikepenz · Aug 2, 2016

As of API Level 24 they have added new methods (and updated the documentation) and flags to the WallpaperManager which allow you to set a Wallpaper not only to the home screen but also to the Lockscreen

To set a Wallpaper to the Lockscreen use the new flag WallpaperManager.FLAG_LOCK, and one of the methods which take int which

WallpaperManager.getInstance(this).setStream(inputStream, null, true, WallpaperManager.FLAG_LOCK);

You can also use one of the following methods

int setStream (InputStream bitmapData,  Rect visibleCropHint,  boolean allowBackup, int which)

int setResource (int resid, int which)

int setBitmap (Bitmap fullImage, Rect visibleCropHint,  boolean allowBackup,  int which)

A nice addition is that you can now also check if you are allowed to set the wallpaper via isSetWallpaperAllowed, and get the current set wallpaper via getWallpaperFile

Check out the updated documentation for the WallpaperManager.