Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set android lock screen image

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

like image 947
robintw Avatar asked Apr 16 '10 15:04

robintw


People also ask

How do I set my lock screen picture?

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.

Can you customize lock screen on Android?

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.


1 Answers

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.

like image 99
mikepenz Avatar answered Sep 28 '22 01:09

mikepenz