系统预制多个launcher时,指定默认启动launcher;并且在默认launcher崩溃时,能再次弹出launcher选择。按home键默认启动指定launcher

	系统预制多个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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心有纤纤结

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值