Android7.0&8.0 默认壁纸修改

1.拷贝自定义壁纸
默认壁纸是default_wallpaper,在/frameworks/base/core/res下面。找到所以的default_wallpaper所在的地方,然后把我们自己的壁纸(custom_wallpaper.png)也拷贝到相应的地方。

2.修改默认壁纸
默认壁纸加载的地方在frameworks/base/core/java/android/app/WallpaperManager.java custom_wallpaper是我们自定义壁纸的图片名字(后面还需添加这个资源字段,否则编译失败,认不到)。

    /**
     * Open stream representing the default static image wallpaper.
     *
     * If the device defines no default wallpaper of the requested kind,
     * {@code null} is returned.
     *
     * @hide
     */
    public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
        final String whichProp;
        final int defaultResId;
        if (which == FLAG_LOCK) {
            /* Factory-default lock wallpapers are not yet supported
            whichProp = PROP_LOCK_WALLPAPER;
            defaultResId = com.android.internal.R.drawable.default_lock_wallpaper;
            */
            return null;
        } else {
            whichProp = PROP_WALLPAPER;
            //Aaron@20170711 F0017
            defaultResId = com.android.internal.R.drawable.custom_wallpaper;
            //defaultResId = com.android.internal.R.drawable.default_wallpaper;
        }
        final String path = SystemProperties.get(whichProp);
        if (!TextUtils.isEmpty(path)) {
            final File file = new File(path);
            if (file.exists()) {
                try {
                    return new FileInputStream(file);
                } catch (IOException e) {
                    // Ignored, fall back to platform default below
                }
            }
        }
        try {
            return context.getResources().openRawResource(defaultResId);
        } catch (NotFoundException e) {
            // no default defined for this device; this is not a failure
        }
        return null;
    }

3.声明资源
在frameworks中添加资源不是直接把图片拷贝过去就可以的,还需要给这个新添加的资源声明。frameworks/base/core/res/res/values/symbols.xml中添加新添加资源的字段。

  <java-symbol type="drawable" name="default_wallpaper" />
  <java-symbol type="drawable" name="custom_wallpaper" />
  <java-symbol type="drawable" name="default_lock_wallpaper" />
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值