怎么用代码更改android中的锁屏壁纸?

时间:2014-10-08 12:08:43

标签: 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);

1 个答案:

答案 0 :(得分:5)

从最新的Android API 24开始,可以使用Lockscreen更新WallpaperManager壁纸并提供FLAG_LOCK标记。

wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK)