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()
}