以编程方式设置 Android 设备的锁屏壁纸

Set lock screen wallpaper of Android device programmatically

有很多壁纸应用程序,您可以在其中更改与主壁纸分开的锁屏壁纸。如果我没记错 API 24 是可以做这种事情的,但是我发现与此相关的文章很少,而且它们太旧了。

WallpaperManager has a number of methods to help you get or set the specific wallpapers. As you want the lock screen wallpaper, use FLAG_LOCK。相关方法包括:

getWallpaperFile(int)

setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)

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