1.添加自定义图片:c_wallpaper.png
路径:frameworks\base\core\res\res\drawable-nodpi\c_wallpaper.png
路径:frameworks\base\core\res\res\drawable-sw600dp-nodpi\c_wallpaper.png
路径:frameworks\base\core\res\res\drawable-sw720dp-nodpi\c_wallpaper.png
2.在symbols.xml 添加资源声明
路径:frameworks\base\core\res\res\values\symbols.xml
<java-symbol type="drawable" name="c_wallpaper" />
<java-symbol type="drawable" name="default_wallpaper" />
<java-symbol type="drawable" name="default_lock_wallpaper" />
3.修改WallpaperManager.java的openDefaultWallpaper 资源引用
路径:frameworks\base\core\java\android\app\WallpaperManager.java
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;
//defaultResId = com.android.internal.R.drawable.default_wallpaper;
//更新成自定义的图片资源
defaultResId = com.android.internal.R.drawable.c_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;
}
4.修改WallpaperManagerService.java的getDefaultWallpaper 资源引用
路径:frameworks\base\services\core\java\com\android\server\wallpaper\WallpaperManagerService.java
private Bitmap getDefaultWallpaper(Context context) {
// int defaultResId = com.android.internal.R.drawable.default_wallpaper;
//更新为自定义墙纸图片
int defaultResId = com.android.internal.R.drawable.c_wallpaper;
InputStream is = context.getResources().openRawResource(defaultResId);
if (is != null) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
return BitmapFactory.decodeStream(is, null, options);
} catch (OutOfMemoryError e) {
Slog.w(TAG, "Can't decode stream", e);
} finally {
IoUtils.closeQuietly(is);
}
}
return null;
}
5.修改Launcher2
路径:packages\apps\Launcher2\res\drawable-nodpi\default_wallpaper.xml
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@*android:drawable/c_wallpaper"
/>
路径:packages\apps\Launcher2\res\drawable-nodpi\wallpaper.xml
<resources>
<string-array name="wallpapers" translatable="false">
<!-- This special drawable references the platform's private
default_wallpaper resource so the user can always choose it. -->
<item>c_wallpaper</item>
<!-- If you want additional bitmap drawable resources to appear in the
wallpaper picker, add them to this list. For each foo.jpg be sure
to include a foo_small.jpg to be used as a thumbnail in the
scrolling gallery widget. -->
</string-array>
</resources>
6.修改DefaultWallpaperInfo.java
路径:packages\apps\WallpaperPicker\src\com\android\wallpaperpicker\tileinfo\DefaultWallpaperInfo.java
private static ResourceWallpaperInfo getPreKKDefaultWallpaperInfo(Context context) {
Resources sysRes = Resources.getSystem();
Resources res = context.getResources();
//int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");
//修改为自定义图片资源
int resId = sysRes.getIdentifier("c_wallpaper", "drawable", "android");
File defaultThumbFile = getDefaultThumbFile(context);
Bitmap thumb = null;
boolean defaultWallpaperExists = false;
if (defaultThumbFile.exists()) {
thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
defaultWallpaperExists = true;
} else {
InputStreamProvider streamProvider = InputStreamProvider.fromResource(res, resId);
thumb = createThumbnail(
streamProvider, context, streamProvider.getRotationFromExif(context), false);
if (thumb != null) {
defaultWallpaperExists = saveDefaultWallpaperThumb(context, thumb);
}
}
if (defaultWallpaperExists) {
return new ResourceWallpaperInfo(sysRes, resId, new BitmapDrawable(res, thumb));
}
return null;
}