How to open the Google Play Store from Android application

How to open the Google Play Store from Android application

Google Play provides several link formats that let you bring users to your products in the way you want, from Android apps, web pages, ads, reviews, articles, social media posts, and more.

There are two general formats for links that are accessible to users on Android devices. The two formats trigger slightly different behaviors on the device:

  • market://. Launches the Play Store app to load the target page.
  • http://. Lets the user choose whether to launch the Play Store app or the browser to handle the request. If the browser handles the request, it loads the target page on the Google Play website.

If you want to link to your products from an Android app, create an Intent that opens a Google Play URL, as shown in the example below.

final String appPackageName = getPackageName();

try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

We use a try/catch block here because an Exception will be thrown if the Play Store is not installed on the target device.

Notw: Any app can register as capable of handling the market://details?id=<appId> uri, if you want to specifically target Google Play check this link.

comments powered by Disqus