如何使用代码更改android中的锁屏壁纸? [英] How can change lockscreen wallpaper in android with code?

查看:144
本文介绍了如何使用代码更改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)

这篇关于如何使用代码更改android中的锁屏壁纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆