回家发射器软件包名,并启动它的最佳方式 [英] Best way to get home launcher packagename and start it

查看:100
本文介绍了回家发射器软件包名,并启动它的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个关于如何回家发射包名称的问题。结果
在Android中,有两种类型的家庭发射器:

I encountered a problem about how to get home launcher packagename.
In android , there are two type of home launcher:


  1. 原单发射器

  2. 3的第三发射器,如去-发射或OEM

所以,我们不能用指定的包名称来启动它。结果
最后,我想出一个解决方案。结果
是否有任何其他更好的方式来做到这一点?结果

So, we can't use specified packagename to start it.
Finally, I figure out a solution.
Is there any other better way to do this?

    //find out the package with ACTION_MAIN & CATEGORY_HOME
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    PackageManager pm = this.getPackageManager();
    List<ResolveInfo> ris = (List<ResolveInfo>) pm.queryIntentActivities(i,
            PackageManager.MATCH_DEFAULT_ONLY);
    Log.i("", ris.size() + "");
    //seletc the first one , doc says the first one is the home launcher currently
    if (ris != null && ris.size() > 0) {
        String pkg = ris.get(0).activityInfo.packageName;
        Log.i("HOME PKG NAME ", pkg);
        //start it 
        i.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
        startActivity(i);
    }

感谢的https://groups.google.com/forum/?fromgroups=#!topic/android-developers/-5aGSOdwJ-8

推荐答案

您可以使用带有类别 CATEGORY_HOME 和行动 ACTION_MAIN

You can use an Intent with Category CATEGORY_HOME and Action ACTION_MAIN.

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

这篇关于回家发射器软件包名,并启动它的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆