6

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

ZeeShaN AbbAs
  • 1,365
  • 2
  • 15
  • 31
  • 1
    I'm developing custom home screen, and i want to launch the default home when required, and I'm facing above same issue. – Palani Dec 29 '11 at 08:32

2 Answers2

12

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);
}
Palani
  • 8,962
  • 11
  • 53
  • 62
1

Are you sure the default Google Android Launcher being installed on your device? If not, then it's truly NULL.

Pete Houston
  • 14,931
  • 6
  • 47
  • 60
  • I am trying this on emulator and for mobile I've tried "com.sonyericsson.home" on my Xperia Arc but it give me force close error doesn't even throw any exception. – ZeeShaN AbbAs Dec 15 '11 at 10:50