Reputation: 28349
I created an app that acts as a launcher, which works as expected, but I'd like to give the user the ability to launch the native Android Launcher.
I know that the package name for the Android Launcher is com.android.launcher
However, when I try to get the Launch intent name from this package by calling
packageManager.getLaunchIntentForPackage("com.android.launcher");
that comes up null.
So, I'm at a loss as to how to use the package name to launch it, and am wondering if perhaps there's some alternate way?
TIA
Upvotes: 2
Views: 4521
Reputation: 1006799
I know that the package name for the Android Launcher is com.android.launcher
Except that may or may not be on any given device. In fact, I would expect it to be on maybe a few percent of devices. Most manufacturers replace the stock home screen with their own.
am wondering if perhaps there's some alternate way?
Use PackageManager
and queryIntentActivities()
to find all activities that support ACTION_MAIN
and CATEGORY_HOME
. Remove your activity from the list. If there is only one left, launch that activity. If there is more than one left, whip up your own chooser to show the available options. That way, no matter what other home screen(s) exists, you will be able to launch it.
UPDATE
Given a ResolveInfo
named launchable
, and an ACTION_MAIN
/CATEGORY_HOME
template Intent
named i
, to launch that activity, do:
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,
activity.name);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(name);
startActivity(i);
Upvotes: 6