执行 adb shell pm list package -f wallpaper 命令,查看壁纸应用路径:
/product/app/MtkWallpaperPicker/MtkWallpaperPicker.apk=com.android.wallpaperpicker
结果中带 Mtk 就可确定MTK有对应用进行重构。其源码路径在
vendor/mediatek/proprietary/packages/apps/WallpaperPicker
查看 WallpaperPickerActivity.java
这里加载了多种不同来源的壁纸资源。
protected void init() {setContentView(R.layout.wallpaper_picker);mCropView = (CropView) findViewById(R.id.cropView);mCropView.setVisibility(View.INVISIBLE);mProgressView = findViewById(R.id.loading);mWallpaperScrollContainer = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);mWallpaperStrip = findViewById(R.id.wallpaper_strip);mCropView.setTouchCallback(new ToggleOnTapCallback(mWallpaperStrip));mWallpaperParallaxOffset = getIntent().getFloatExtra(WallpaperUtils.EXTRA_WALLPAPER_OFFSET, 0);mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);// Populate the saved wallpapersmSavedImages = new SavedWallpaperImages(this);populateWallpapers(mWallpapersView, mSavedImages.loadThumbnailsAndImageIdList(), true);// Populate the built-in wallpapers. 这里是加载预置壁纸的地方。ArrayList<WallpaperTileInfo> wallpapers = findBundledWallpapers();populateWallpapers(mWallpapersView, wallpapers, false);// Load live wallpapers asynchronouslynew LiveWallpaperInfo.LoaderTask(this) {@Overrideprotected void onPostExecute(List<LiveWallpaperInfo> result) {populateWallpapers((LinearLayout) findViewById(R.id.live_wallpaper_list),result, false);initializeScrollForRtl();updateTileIndices();}}.execute();// Populate the third-party wallpaper pickerspopulateWallpapers((LinearLayout) findViewById(R.id.third_party_wallpaper_list),ThirdPartyWallpaperInfo.getAll(this), false /* addLongPressHandler */);// Add a tile for the GalleryLinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);masterWallpaperList.addView(createTileView(masterWallpaperList, new PickImageInfo(), false), 0);// Select the first item; wait for a layout pass so that we initialize the dimensions of// cropView or the defaultWallpaperView firstmCropView.addOnLayoutChangeListener(new OnLayoutChangeListener() {@Overridepublic void onLayoutChange(View v, int left, int top, int right, int bottom,int oldLeft, int oldTop, int oldRight, int oldBottom) {if ((right - left) > 0 && (bottom - top) > 0) {if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) {onClick(mWallpapersView.getChildAt(mSelectedIndex));setSystemWallpaperVisiblity(false);}v.removeOnLayoutChangeListener(this);}}});
public ArrayList<WallpaperTileInfo> findBundledWallpapers() {final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24);//这里是根据xml中的配置加载资源,我们改这里。Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();if (r != null) {try {Resources wallpaperRes = getPackageManager().getResourcesForApplication(r.first);addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);} catch (PackageManager.NameNotFoundException e) {}}// Add an entry for the default wallpaper (stored in system resources)
//这里是默认的那张WallpaperTileInfo defaultWallpaperInfo = DefaultWallpaperInfo.get(this);if (defaultWallpaperInfo != null) {bundled.add(0, defaultWallpaperInfo);}return bundled;}
参考:android WallpaperPicker7.0源码分析_com.android.wallpaperpicker-CSDN博客
public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() {return new Pair<>(getApplicationInfo(), R.array.wallpapers);}
查询xml中wallpapers 配置。
<string-array name="wallpapers" translatable="false">
<item>wp1</item>
</string-array>
可以在此处添加多张图片
把图片放到 drawable 下,这里要注意需要同时配置*_small.jpg图片;
如 wp1.jpg, wp1_small.jpg.
编译 MtkWallpaperPicker 模块,然后push到机器中,杀死wallpaper进程即可。