How do I open the Google Play Store directly from the app?

Asked 2 years ago, Updated 2 years ago, 22 views

I put the code below to open the Google Play Store.

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.

This gives you the option to open it between browser and playstore, but what I want is to connect to the play store right away, so how do I do that?

android google-play-store

2022-09-21 14:16

1 Answers

You can put market:// in front of it.

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
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)));
}

Like this. The try/catch syntax is to deal with the part when the PlayStore is not installed.


2022-09-21 14:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.