javaandroidwidgetlockscreenwallpaper

Is there any way of changing LockScreen Wallpaper/photo in Android programmatically


I want to change the lockscreen wallpaper of Android. I was able to change home screen wallpaper through WallpaperManager.setResource

But I am unable to set LockScreen Wallpaper

Also is there any way to change it over time automatically?


Solution

  • Frist Create Bitmap source from drawable Resource

    Bitmap icon = BitmapFactory.decodeResource(getViewContext().getResources(), R.drawable.wall);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            WallpaperManager wallpaperManager =WallpaperManager.getInstance(getViewContext());
            try {
                wallpaperManager.setBitmap(icon, null, true, WallpaperManager.FLAG_LOCK);
            } catch (IOException e) {
                e.printStackTrace();
            }