如何设置安卓锁屏图片
我刚刚开始使用 android 编程,想看看是否有一种方法可以以编程方式设置锁定屏幕图像。我在API中找到了各种设置壁纸的方法,但我似乎找不到设置锁屏图像的等效方法。
我看过各种帖子说通过添加小部件或应用程序位来自定义锁定屏幕是不可能的,但肯定有一种方法可以以编程方式设置图像?
干杯,
罗宾
I'm just getting started with android programming, and want to see if there is a way to programmatically set the lock screen image. I've found various ways of setting the wallpaper in the API, but I can't seem to find the equivalent ways of setting the lock screen image.
I've seen various posts saying that customising the lock screen by adding widgets or bits of applications is not possible, but surely there must be a way to set the image programmatically?
Cheers,
Robin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
还有另一种方法可以做到这一点。首先,您需要将要设置锁屏的图片保存在一个文件夹中(假设它名为“appName”)。然后,使用以下代码打开图库,图库打开后,引导用户打开“appName”文件夹,并选择系统图库中的图片。在图库中,用户可以将图片设置为壁纸或锁屏纸。
// 此代码用于打开画廊。
startActivity(new Intent(Intent.ACTION_SET_WALLPAPER));
There is another way to do this. at first ,you need save the pic which you wanna set in lockedscreen in a folder(suppose it's called "appName").and then ,use following code to open gallery, after gallery has opened.lead user to open "appName" folder ,and choose the pic in gallery of system. in the gallery,user can set a pic as wallpaper or lockscreen paper.
// this code to open gallery.
startActivity(new Intent(Intent.ACTION_SET_WALLPAPER));
api30+ 的用法
usage for api30+
自API 级别 24 起,您可以为主屏幕、锁定屏幕或两者设置壁纸:
来源
Since API level 24, you can set wallpaper to your home screen, lock screen, or both:
source
从 API 级别 24 开始,他们添加了新方法(并更新了文档 )和
WallpaperManager
的标志,它允许您不仅在主屏幕上设置Wallpaper
,而且还可以在Lockscreen
上设置
使用新标志 WallpaperManager.FLAG_LOCK,以及采用Lockscreen
的 >Wallpaperint which
的方法之一您还可以使用以下方法之一
一个不错的补充是,您现在还可以通过
isSetWallpaperAllowed
检查是否允许设置壁纸,并通过getWallpaperFile
检查 获取当前设置的壁纸更新
WallpaperManager
的文档。As of API Level 24 they have added new methods (and updated the documentation) and flags to the
WallpaperManager
which allow you to set aWallpaper
not only to the home screen but also to theLockscreen
To set a
Wallpaper
to theLockscreen
use the new flag WallpaperManager.FLAG_LOCK, and one of the methods which takeint which
You can also use one of the following methods
A nice addition is that you can now also check if you are allowed to set the wallpaper via
isSetWallpaperAllowed
, and get the current set wallpaper viagetWallpaperFile
Check out the updated documentation for the
WallpaperManager
.Android 中没有“锁屏图像”。在原生 Android、HTC Sense、MOTOBLUR 等之间肯定不存在相同的“锁屏图像”概念。这根本不是 Android SDK 的一部分。
Rijk 先生指出的该项目是一种安全违规行为,冒充锁屏替代品。
There is no "lock screen image" in Android. There most certainly is no "lock screen image" concept that is the same between stock Android, HTC Sense, MOTOBLUR, etc. This simply is not part of the Android SDK.
The project that Mr. Rijk points to is a security violation that pretends to be a lock screen replacement.
有一种方法可以在三星设备上做到这一点。在意图中你可以添加额外的内容。
我只在一些三星手机上测试过这一点,并不能保证这在未来一段时间内不会出现问题。谨慎使用。
There is a way to do it on Samsung devices. In the intent you can put an extra.
I've only tested this on some Samsung phones and there's no guarantee that this won't break some time in the future. Use with caution.
您可以使用 WalpaperManager 类的这三个方法,但它仅适用于无版本设备或更高版本:-
这三个方法的参数:-
Bitmap/resid/inputStreamData :- 该参数接受数据
visibleCropHint:- 该参数接受 Rect 对象,其中主要用于裁剪功能,更多信息请参考 Android 开发者参考网站 ,如果您不想要裁剪功能,您也可以传递 null。allowBackup
:-boolean: true 如果操作系统允许备份此壁纸图像以便恢复到未来的设备;否则为假。
其中:-它是帮助您配置锁屏壁纸和主壁纸的最重要参数之一。对于锁屏使用 WalpaperManager.FLAG_LOCK 对于家庭壁纸使用 FLAG_SYSTEM
我举一个例子来让您了解如何使用它:-
有关更多信息,请访问 Android 开发者壁纸管理器参考
You can use these three methods of WalpaperManager class but it will only work for nought version devices or above it:-
Parameter of these three methods:-
Bitmap/resid/inputStreamData :-this parameter accept data
visibleCropHint:-this parameter accept Rect object which is mainly used for Cropping functionality, for more information refer to Android developer reference website, you can also pass null if u don't want cropping functionality
allowBackup:-boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
which:-It is one of the most important parameter which helps you to configure wallpaper for lock screen and home wallpaper. for lock screen use WalpaperManager.FLAG_LOCK and for home wallpaper use FLAG_SYSTEM
I am giving one example to make you understand how to use it:-
for more information visit Android developer wallpaper manager reference