call the default home screen from application

时光怂恿深爱的人放手 提交于 2019-12-01 07:57:00

问题


I need to call the default home screen that comes with my phone from my application which is also a home screen app. I've tried searching and find this

    ArrayList<Intent> intentList = new ArrayList<Intent>();
    Intent intent=null;
    final PackageManager packageManager=getPackageManager();
    for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new 
                  Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 
                                                        PackageManager.MATCH_DEFAULT_ONLY)) {
    intent=packageManager.getLaunchIntentForPackage(
                          resolveInfo.activityInfo.packageName);
    intentList.add(intent);
    }

this code is working for the all the other launchers but not for the default launcher. I tried using break points in code and found that at 0 index of list there should be default launcher intent but intent does'nt hold the value. Do I need some kind of permission thanks


回答1:


you can just simple get the name and class from ResolveInfo and make intent manualy like for sonyercisson the package name is "com.sonyericsson.home" and class is "com.sonyericsson.home.HomeActivity"

   Intent intent = new Intent();
   intent.setClassName("com.sonyericsson.home", "com.sonyericsson.home.HomeActivity");
   intent.addCategory(Intent.CATEGORY_LAUNCHER);
   startActivity(intent);

it works




回答2:


Hope this will do.

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


来源:https://stackoverflow.com/questions/8515990/call-the-default-home-screen-from-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!