open android own launcher from my application

不想你离开。 提交于 2019-12-03 03:26:21

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);
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!