从Android N开始,原生系统增加了锁屏壁纸开关:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
/** If true, the lockscreen will show a distinct wallpaper */
private static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
要设置出厂默认锁屏壁纸,修改如下代码即可实现:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
public Bitmap getBitmap() {
if (mCached) {
return mCache;
}
if (!mWallpaperManager.isWallpaperSupported()) {
mCached = true;
mCache = null;
return null;
}
LoaderResult result = loadBitmap(mCurrentUserId, mSelectedUser);
if (result.success) {
mCached = true;
mUpdateMonitor.setHasLockscreenWallpaper(result.bitmap != null);
mCache = result.bitmap;
}
//add begin : 第一次开机加载失败,尝试读取系统资源default_lock_wallpaper.jpg,然后写入到锁屏壁纸文件中,并重新loadBitmap
if (mCache == null) {
try {
mWallpaperManager.setStream(
mContext.getResources().openRawResource(com.android.internal.R.drawable.default_lock_wallpaper),
null,
true,
WallpaperManager.FLAG_LOCK);
result = loadBitmap(mCurrentUserId, mSelectedUser);
if (result.success) {
mCached = true;
mUpdateMonitor.setHasLockscreenWallpaper(result.bitmap != null);
mCache = result.bitmap;
}
} catch (IOException e) {
Log.e(TAG, "can not set default lockscreen wallpaper");
}
}
//add end
return mCache;
}
然后放入系统资源图片default_lock_wallpaper即可。