Android5.1 壁纸来源选项中有两个“壁纸”选项
【问题】
系统语言为中文,打开 设置->显示->壁纸->查看显示
可以看到设置菜单中有两个壁纸选项显示
系统语言为英文,菜单中有两个"Wallpapers"选项
【log】
01-12 12:26:47.194: D/SubSettings(7598): Launching fragment com.android.settings.WallpaperTypeSettings
【debug】
找到WallpaperTypeSettings这个文件
点击“显示”->“壁纸”选项,弹出“选择壁纸来源”(Choose wallpaper from)页面
即进入下面这个文件
WallpaperTypeSettings.java (packages\apps\settings\src\com\android\settings)
WallpaperTypeSettings extends SettingsPreferenceFragment implements Indexable
此类继承自SettingsPreferenceFragment
/**
* Base class for Settings fragments, with some helper functions and dialog management.
*/
public class SettingsPreferenceFragment extends PreferenceFragment implements DialogCreatable
壁纸来源的设置选项是动态加载的。
WallpaperTypeSettings.java中有populateWallpaperTypes()方法
private void populateWallpaperTypes() { // Search for activities that satisfy the ACTION_SET_WALLPAPER action final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); final PackageManager pm = getPackageManager(); final List<ResolveInfo> rList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); final PreferenceScreen parent = getPreferenceScreen(); parent.setOrderingAsAdded(false); // Add Preference items for each of the matching activities for (ResolveInfo info : rList) { Preference pref = new Preference(getActivity()); Intent prefIntent = new Intent(intent); prefIntent.setComponent(new ComponentName( info.activityInfo.packageName, info.activityInfo.name)); pref.setIntent(prefIntent); CharSequence label = info.loadLabel(pm); if (label == null) label = info.activityInfo.packageName; pref.setTitle(label); parent.addPreference(pref); } }
一共找到4个packages能够设置壁纸
com.android.launcher -- 壁纸选项
com.cyanogenmod.trebuchet -- 壁纸,包括照片与动态壁纸等等
com.android.gallery3d -- 图库
com.android.wallpaper.livepicker -- 动态壁纸
在这里我选择性地不加载com.android.launcher
修改后的代码:
//delete a wallpaper option if (!info.activityInfo.packageName.equals("com.android.launcher")){ parent.addPreference(pref); } //fix bug end
最后效果,选择壁纸来源界面只有3个选项
/**-------------------------------附录-------------------------------*/
Wallpaper_chooser.xml (packages\apps\launcher2\res\layout)
设置壁纸时的页面。上面是壁纸,下面是一个设置button。