Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching default android launcher programmatically

I'm looking for a way to launch the default android launcher programatically, something perhaps like the code below. Or do I have to add something to the manifest file? Thanks!

Intent intent = new Intent();
intent.setClassName("com.android.launcher", "Launcher");
startActivity(intent);
like image 486
dosa Avatar asked Jul 15 '11 10:07

dosa


People also ask

How do I change the default program launcher programmatically?

Select the "MxDefaultLauncherTutorial" app and the app will open. Enter the package name of Galaxy Launcher application that we had obtained previously (com.epic.launcher.tw). Click Set Default Launcher button. The app will now set Galaxy Launcher as the default launcher application.

How do I launch the default launcher?

Change default Android launcher With some Android phones you head to Settings > Home, and then you choose the launcher you want. With others you head to Settings > Apps and then hit the settings cog icon in the top corner where you'll then options to change default apps.

How do I change launcher activity in Android programmatically?

The easiest way is to make MainActivity launcher activity, as usual. Then check in MainActivity#onCreate(Bundle) via SharedPreferences if the user already logged in and, if not, start LoginActivity immediately.


1 Answers

Have you tried this?

startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));

(I haven't tried it myself, because my use case is a little more complicated---I've replaced the launcher, and I want to call the old launcher...)

I've also discovered that you can use the package manager to look through all activities that meet some intent filter criteria. For example, if you want to find all the activities marked as the home default home activity, use this:

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))
{
    if(!getPackageName().equals(resolveInfo.activityInfo.packageName))  //if this activity is not in our activity (in other words, it's another default home screen)
    {
        intent=packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName));
        break;
    }
}

Note that I have replaced the default home screen on my device---that's why I have to make sure the activity I found is not the activity that's running! If you haven't replaced the default home activity, you don't need this check---just use the first (and probably the only) default home activity.

(Note that I still can't launch the old launcher from my launcher, perhaps because the old launcher keeps a record of the default launcher, which is my new launcher, and simply calls back to it. I don't know. But at least it doesn't crash, and I would guess that, if you haven't replaced the old home screen, it just might work.)

like image 180
Garret Wilson Avatar answered Nov 15 '22 19:11

Garret Wilson