当前位置:   article > 正文

[FAQ03426]android 4.4当系统存在多个Launcher时,如何设 置开机自动进入默认的Launcher?_android 4.4默认设置launcher

android 4.4默认设置launcher
[DESCRIPTION]
开机完成并解锁后,如果系统存在多个Launcher,系统会弹出一个选择框让用户选择
进入某个Launcher。如果用户不想选择,而是想直接进入某一个默认的Launcher,要
怎么修改?经测试可以实现本功能。
[SOLUTION]
修改ActivityManagerService.java的startHomeActivityLocked方法
boolean startHomeActivityLocked(int userId, String reason) {
if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
&& mTopAction == null) {
// We are running in factory test mode, but unable to find
// the factory test app, so just sit around displaying the
// error message and don't try to start anything.
return false;
}
/**
* mtk add
* set default launcher
*/
ComponentName DefaultLauncher=new
ComponentName("com.android.launcher3","com.android.launcher3.Launcher"); //此处设置默认Launcher的包名和
类名
//Slog.d(TAG,"set default launcher");
final PackageManager mPm = mContext.getPackageManager();
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()];
for (int i = 0; i < homeActivities.size(); i++) {
final ResolveInfo candidate = homeActivities.get(i);
//Slog.d(TAG,"homeActivities"+candidate);
final ActivityInfo info = candidate.activityInfo;
ComponentName activityName = new ComponentName(info.packageName, info.name);
mHomeComponentSet[i] = activityName;
}
IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
List<ComponentName>Activities=new ArrayList();
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet,

DefaultLauncher);
/**
* set default launcher end
*/
Intent intent = getHomeIntent();
ActivityInfo aInfo =
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
......
PS:
1.如果用户在设置->应用程序->管理应用程序->所有应用程序列表,找到之前设置的
默认Launcher,并取消了默认值,系统会重新弹出launcher选择框。但重启后会进入
上述代码设置的默认Launcher。
2.如果用户在设置->主屏幕中修改了默认的Launcher,下次重启后将进入修改后的

Launcher



 
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/787711
推荐阅读
相关标签
  

闽ICP备14008679号