如何使用代码在安卓手机上更改锁屏壁纸?

4

我可以更改主屏幕壁纸,但我无法更改锁定屏幕壁纸。

                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个回答

7

最新的Android API 24版本中,可以通过使用WallpaperManager并提供FLAG_LOCK标志来更新Lockscreen壁纸。

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

它在我的手机上工作,但在Marshmallow手机上不起作用。 - Bipin Bharti
@RobbyPatel 如所述,该功能是在API 24中添加的(因此在API 24之前的Android版本中不可用),并且永远不会得到支持。 - mikepenz
但一些三星手机有可用的锁屏壁纸,它是如何工作的? - Bipin Bharti
由于三星正在修改SystemUI,因此他们可以做任何他们想做的事情。但是,他们没有通过Android SDK提供API来允许您更改它。 - mikepenz
我的设备版本是24,它不能工作。 - Amarjit
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接