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
Go to Settings > Personalization > Lock screen. Under Background, select Picture or Slideshow to use your own picture(s) as the background for your lock screen.
Once you access the Wallpapers section, look for the Lock Screen customization option or select any image appearing in the wallpaper section. It will give you an option to apply the wallpaper on your Homepage or lock screen. Note: Some Android smartphones offer this option in their Gallery app as well.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With