How to redirect User to default launcher in an android app?

若如初见. 提交于 2019-12-04 12:57:01

try this :

goHome.setClassName("com.android.launcher", "com.android.launcher2.Launcher");

Use:

    PackageManager pm = getPackageManager();
    Intent i = new Intent("android.intent.action.MAIN");
    i.addCategory("android.intent.category.HOME");
    List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
    if (lst != null) {
       for (ResolveInfo resolveInfo : lst) {
           try {
           Intent home = new Intent("android.intent.action.MAIN");
           home.addCategory("android.intent.category.HOME");
           home.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
           startActivity(home);
           break;
           } catch (Throwable t) {
               t.printStackTrace();
           }
       }
    }

In case you have a Samsung device, the following code worked for me:

Intent goHome = new Intent(Intent.ACTION_MAIN);
        goHome.setClassName("com.sec.android.app.launcher", "com.android.launcher2.Launcher");
        startActivity(goHome);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!