-1

i want to open an another app activity from my app, if the app is not installed go to the play store to install the app.

my code is working fine but its only open the app from it's package name, it's not opening activity.

Code:

public void startApplication(String packageName)
{
    try
    {
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");

        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);

        for(ResolveInfo info : resolveInfoList)
            if(info.activityInfo.packageName.equalsIgnoreCase(packageName))
            {
                launchComponent(info.activityInfo.packageName, info.activityInfo.name);
                return;
            }

        // No match, so application is not installed
        showInMarket(packageName);
    }
    catch (Exception e)
    {
        showInMarket(packageName);
    }
}

private void launchComponent(String packageName, String name)
{
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setComponent(new ComponentName(packageName, name));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    startActivity(intent);
}

private void showInMarket(String packageName)
{
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}
ahsen mughal
  • 39
  • 1
  • 1
  • 5

1 Answers1

0

Try

public void startApplication(String packageName) {
    Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName);
    if (launchIntent != null) { 
        startActivity(launchIntent);
    } else {
        showInMarket(packageName);
    }
}
rohanr22
  • 1
  • 1
  • No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.nouvellesapplis.lt2.view.LoginActivity – ahsen mughal Mar 25 '17 at 19:08