Harshil Rastogi Harshil Rastogi - 1 month ago 8
Android Question

How to open ola app from my app?

What is the String uri to open the ola app from my app?

I have tried this

try {
pm.getPackageInfo("com.olacabs.customer",PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
try {
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.olacabs.customer")));
} catch (android.content.ActivityNotFoundException anfe) {
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer")));
}
}

Answer
  Uri uri = Uri.parse("market://details?id=com.olacabs.customer");
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer")));
    }

If Ola app is already installed then you can call Launcher like this

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.olacabs.customer");
  if (launchIntent != null) { 
     startActivity(launchIntent);//null pointer check in case package name was not found
  }

Final code will be like this: Final Code:

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.olacabs.customer");
      if (launchIntent != null) { 
         startActivity(launchIntent);//null pointer check in case package name was not found
      }else
      {
        Uri uri = Uri.parse("market://details?id=com.olacabs.customer");
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
       try {
          startActivity(goToMarket);
       } catch (ActivityNotFoundException e) {
           startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer")));
      }
  }
Comments