I can't change lock screen wallpaper in my kotlin wallpaper app
-
Here fl_iv is the frame layout containing the imageview which showcases the image. I have set up a button there which allows user to use the image as LOCK SCREEN wallpaper. id of that button is lock_screen. Please try to be descriptive as i am new to this language I tried this code for lock screen but its not working.
lock_screen.setOnClickListener {
val wpManager = WallpaperManager.getInstance(this)
val myBitmap: Bitmap = fl_iv.drawToBitmap()
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wpManager.setBitmap(myBitmap, null, true, WallpaperManager.FLAG_LOCK)
}
else{
return@setOnClickListener
}
} catch (ex: IOException) {
ex.printStackTrace()} }
-
Here fl_iv is the frame layout containing the imageview which showcases the image. I have set up a button there which allows user to use the image as LOCK SCREEN wallpaper. id of that button is lock_screen. Please try to be descriptive as i am new to this language I tried this code for lock screen but its not working.
lock_screen.setOnClickListener {
val wpManager = WallpaperManager.getInstance(this)
val myBitmap: Bitmap = fl_iv.drawToBitmap()
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wpManager.setBitmap(myBitmap, null, true, WallpaperManager.FLAG_LOCK)
}
else{
return@setOnClickListener
}
} catch (ex: IOException) {
ex.printStackTrace()} }
-
VipulSh wrote:
but its not working
Unfortunately that does not explain what your problem is. Please edit your question and explain what happens when you run your code (assuming it is your code, and not something downloaded from the internet).
Yea i tried to write it according to android documentation. It does nothing. Not even an error. It just doesn't do anything. I want to click it and set my bitmap image as lock screen wallpaper but nothing happens. What i should change in it to make it work for me?
-
Yea i tried to write it according to android documentation. It does nothing. Not even an error. It just doesn't do anything. I want to click it and set my bitmap image as lock screen wallpaper but nothing happens. What i should change in it to make it work for me?
-
Sorry, no idea. The only way to find out what is happening is by using the debugger. Something in your code must be wrong, or using the system in the wrong way.
-
It would have been easier if logcat actually declared some error. but as no error is showing up idk whats happening