I have a click button that sets the wallpaper from URL both for lock and home screen but it does not work for lockScreen in API level 28 or lower

105 views Asked by At

I am tring to set an image from URL as wallaper for both home screen and lock screen.it is not working for lock screen for API level 28 or lower but works for home screen.

val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
                    StrictMode.setThreadPolicy(policy)
                    var input: InputStream? = null
                    try {
                        input = URL(intent).openStream()
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            val wallpaperManager = WallpaperManager.getInstance(applicationContext)
                            wallpaperManager.setStream(
                                input, null, true,
                                WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM
                            )
                            Toast.makeText(this, "Wallpaper set successfully!", Toast.LENGTH_SHORT)
                                .show()
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
0

There are 0 answers