系统预制多个launcher时,指定默认启动launcher;并且在默认launcher崩溃时,能再次弹出launcher选择;
1、这个问题首先是先考虑修改launcher的优先级,<intent-filter android:priority="2">;
这种方法试了下没起作用,而且考虑到修改优先级后,每次启动都会首先检测launcher优先级,也就是说,即使默认launcher崩溃后,还是会重新加载默认的launcher;这种方式不行;
2、设置默认luancher有很多方式,下面是一种;后面用计时器计时的方法来判断launcher是否要切换,
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
}
Intent intent = getHomeIntent();
ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
if (aInfo != null) {
/ /add begin
PackageManager pm = mContext.getPackageManager();
Intent newintent = new Intent(Intent.ACTION_MAIN);
newintent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(newintent, 0);
//判断带有Intent.CATEGORY_HOME标签的所有activity中如果有你指定的activity则替换
if(resolveInfoList != null){
int size = resolveInfoList.size();
cTime = cTime + 1 ;
for(int i = 0; i < size; i++){
ResolveInfo rInfo = resolveInfoList.get(i);
if(rInfo.activityInfo.name.equals("com.landicorp.spdemo.MainActivity")){
aInfo = rInfo.activityInfo;//设置默认启动launcher
}
}
}
if(cTime > 3){
//默认launcher崩溃4次后,弹出launcher选择
aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
cTime = 0;//计数
}else{
//timer.schedule(task, 4000);
}
//add end
intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
// Don't do this if the home app is currently being
// instrumented.
按home键默认启动指定launcher
frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
public boolean configureContentView(List<Intent> payloadIntents, Intent[] initialIntents,
List<ResolveInfo> rList) {
// The last argument of createAdapter is whether to do special handling
// of the last used choice to highlight it in the list. We need to always
// turn this off when running under voice interaction, since it results in
// a more complicated UI that the current voice interaction flow is not able
// to handle.
mAdapter = createAdapter(this, payloadIntents, initialIntents, rList,
mLaunchedFromUid, mSupportsAlwaysUseOption && !isVoiceInteraction());
boolean rebuildCompleted = mAdapter.rebuildList();
//modify begin
String homeIn= payloadIntents+"";
Log.e("lyl","homeIn "+homeIn);
if(homeIn != null){
if("false".equals(SystemProperties.get("persist.sys.mNavigation")) && homeIn.contains("android.intent.category.HOME")){
Intent mIntent = new Intent();
ComponentName comp = new ComponentName("com.ellabook.mix", "com.ellabook.mix.SplashActivity");
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.VIEW");
startActivity(mIntent);
finish();
return true;
}
//end