Android7.0&8.0 默认壁纸修改

来源:互联网 发布:淘宝有哪些孕妇装店 编辑:程序博客网 时间:2024/06/05 07:14

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" />