android - 如何使用代码更改android中的锁屏壁纸?

标签 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 并提供 FLAG_LOCK 标志来更新Lockscreen 墙纸。

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

关于android - 如何使用代码更改android中的锁屏壁纸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26256540/

相关文章:

java - 由于 ResourceCycle 错误,无法在 Android Studio 中生成 apk 文件

android - 带有背景图像的慢速应用程序

java - 从内部方法返回一个对象

java - onClick 在对话框内的 ListView 中的 ImageView

android - SoundPool类型的方法load(Context,int,int)不适用,方法getSystemService(String)未定义

android - 在 ActionBar title-android 中滚动

android - 当我同步 gradle 时,android Studio 3.0 出现错误。错误:Cause: unable to find valid certification path to requested target

android - Admob Interstitial 关闭现有 Activity

android - Android Froyo (2.2) 的 shouldInterceptRequest 等效项

android - RecyclerView拖动第一个项目时,它跳到底部