如何使用代码更改android中的锁屏壁纸?
问题描述:
我可以更改主屏幕墙纸,但是我不能更改锁定屏幕墙纸,
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
wallpaperManager.setBitmap(bitmap);
wallpaperManager.suggestDesiredDimensions(width, height);
答
从最新的Android API 24开始,可以使用 WallpaperManager
更新 Lockscreen
墙纸.并提供 FLAG_LOCK
标志.
As of the latest Android API 24 it is possible to update the Lockscreen
wallpaper by using the WallpaperManager
and providing the FLAG_LOCK
flag.
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK)