I implemented a wallpaperServices to replace the wallpaperServices in SystemUI
Now I can display images freely in MyWallpaperServices。
But,When other applications use WallpaperManager.getInstance(this).drawable, the obtained drawable is still the original WallpaperServices image。
val wallpaperManager = WallpaperManager.getInstance(this)
val setWallpaperComponentMethod =
WallpaperManager::class.java.getMethod(
"setWallpaperComponent",
ComponentName::class.java
)
val componentName = ComponentName(this, MyWallpaperServices::class.java)
setWallpaperComponentMethod.invoke(wallpaperManager, componentName)
What do I need to do so that WallpaperManager.getInstance(this).drawable returns the image of MyWallpaperServices
I tried calling the WallpaperManager.setBitmap method in MyWallpaperServices
private fun drawWallpaper(width: Int, height: Int) {
val canvas = surfaceHolder.lockCanvas()
if (canvas != null) {
val wallpaper = getOrLoadBitmap(wallpaperResources[currentWallpaperIndex], width, height)
canvas.drawBitmap(wallpaper, 0f, 0f, null)
surfaceHolder.unlockCanvasAndPost(canvas)
WallpaperManager.getInstance(applicationContext).setBitmap(wallpaper)
}
}
This will cause MyWallpaperServices to become invalid and return to the original wallpaperServices