现在Android的壁纸软件也是百花齐放,种类繁多自己也打算搞一个,这里先打一个广告 乖咔壁纸下载:
对于壁纸所主要使用到的我直接上代码
/**
* @author: JayQiu
* @date: 2022/3/10
* @description:
*/
object WallpaperHelper {
fun setWallpaper(bitmap: Bitmap, mApply: Apply): Boolean {
val wallpaperManager = try {
WallpaperManager.getInstance(baseApplication)
} catch (e: Exception) {
e.printStackTrace()
null
}
wallpaperManager ?: return false
val height =
ScreenUtils.getScreenHeight(baseApplication) + ScreenUtils.getNavigationBarHeight(
baseApplication
) + ScreenUtils.getStatusBarHeight(baseApplication)
wallpaperManager.suggestDesiredDimensions(
ScreenUtils.getScreenWidth(baseApplication),
height
)
if (mApply == Apply.HOMESCREEN_LOCKSCREEN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wallpaperManager.setBitmap(
bitmap, null, true, WallpaperManager.FLAG_SYSTEM
)
wallpaperManager.setBitmap(
bitmap, null, true, WallpaperManager.FLAG_LOCK
)
return true
}
}
if (mApply == Apply.HOMESCREEN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wallpaperManager.setBitmap(
bitmap, null, true, WallpaperManager.FLAG_SYSTEM
)
return true
}
wallpaperManager.setBitmap(bitmap)
return true
}
if (mApply == Apply.LOCKSCREEN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wallpaperManager.setBitmap(
bitmap, null, true, WallpaperManager.FLAG_LOCK
)
return true
}
}
return false
}
}
ScreenUtils 中是设置获取手机的快高的,这里更具自己的需要去设置