Android 设置系统桌面壁纸

本篇主要讲下如何设置系统桌面壁纸.

代码如下:

java 复制代码
    public static void setLauncherWallPaper(Context context, Bitmap bitmap) throws IOException {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            final int result;
            try {
                result = WallpaperManager.getInstance(context).setBitmap(bitmap, null, false, WallpaperManager.FLAG_SYSTEM);
            } catch (Throwable e) {
                throw new IOException(e);
            }
            if (result == 0) {
                throw new IOException("setLauncherWallPaper failed");
            }
        } else {
            try {
                WallpaperManager.getInstance(context).setBitmap(bitmap);
            } catch (Throwable e) {
                throw new IOException(e);
            }
        }
    }

本地调用如下:

java 复制代码
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.wallpaper);
        try {
            setLauncherWallPaper(this,bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
相关推荐
追光天使42 分钟前
【Mac】和【安卓手机】 通过有线方式实现投屏
android·macos·智能手机·投屏·有线
小雨cc5566ru1 小时前
uniapp+Android智慧居家养老服务平台 0fjae微信小程序
android·微信小程序·uni-app
一切皆是定数2 小时前
Android车载——VehicleHal初始化(Android 11)
android·gitee
一切皆是定数2 小时前
Android车载——VehicleHal运行流程(Android 11)
android
problc2 小时前
Android 组件化利器:WMRouter 与 DRouter 的选择与实践
android·java
图王大胜3 小时前
Android SystemUI组件(11)SystemUIVisibility解读
android·framework·systemui·visibility
服装学院的IT男7 小时前
【Android 13源码分析】Activity生命周期之onCreate,onStart,onResume-2
android
Arms2067 小时前
android 全面屏最底部栏沉浸式
android
服装学院的IT男7 小时前
【Android 源码分析】Activity生命周期之onStop-1
android
ChinaDragonDreamer10 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin