0

I am using a button with id home_screen to set up an image in the framelayout fl_iv as homescreen wallpaper. But when i click on that, it sets up the image as both homescreen wallpaper and lockscreen wallpaper. How to make it just change the home wallpaper? The code goes as:

home_screen.setOnClickListener {
            Toast.makeText(this@SetWallpaperActivity, "Please Wait. Setting Up", Toast.LENGTH_SHORT).show()

                val result: Bitmap = fl_iv.drawToBitmap()

                val wallpaperManager = WallpaperManager.getInstance(this)

                try {
                    wallpaperManager.setBitmap(result)

                } catch (ex: IOException) {
                    ex.printStackTrace()
                }
                Toast.makeText(this@SetWallpaperActivity, "All Done :)", Toast.LENGTH_SHORT).show()


        }

1 Answers1

0

Try specifying FLAG_SYSTEM in your wallpaper manager

wallpaperManager.setBitmap(result, null, true, WallpaperManager.FLAG_SYSTEM)

Jaime
  • 378
  • 2
  • 7
  • I tried that but it says that it requires android api level 24 to call this funtion but the minimum set is 22. i was previously using wallpaperManager.setBitmap(result) , it managed to change both home screen and lock screen as low as api 22, so i think there should be a way to a home screen change alone in api 22 and above – Vipul Sharma Jun 08 '20 at 00:07