Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open android own launcher from my application

hi Its been 2 days looking for this simple problem. I want to launch Android own launcher from my application EVEN if its not set as default.

   final PackageManager packageManager=getPackageManager();
   Intent intent = packageManager.getLaunchIntentForPackage("com.android.launcher");

this return null for Android own launcher but if I try custom launcher is give me successfully

like image 439
ZeeShaN AbbAs Avatar asked Dec 15 '11 10:12

ZeeShaN AbbAs


People also ask

How do I set an app as a 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 open Android launcher?

Step 1: Run the Settings app. Step 2: Tap Apps, then swipe over to the All heading. Step 3: Scroll down until you find the name of your current launcher, then tap it.


1 Answers

Found the solution, after investigating source code of getLaunchIntentForPackage. As per documentation,

The current implementation will look first for a main activity in the category CATEGORY_INFO, next for a main activity in the category CATEGORY_LAUNCHER, or return null if neither are found.

So, the function don't look for CATEGORY_HOME, i rewrote it in following way, it worked perfectly.

Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_HOME);
intentToResolve.setPackage("com.android.launcher");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null) 
{
    Intent intent = new Intent(intentToResolve);
    intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
}
like image 165
Palani Avatar answered Sep 28 '22 01:09

Palani