I have open the Google Play store using the following code
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse(\"https://play.goo
Some of the answers to this question are outdated.
What worked for me (in 2020) was to explicitly tell the intent to skip the chooser and directly open the play store app, according to this link:
"If you want to link to your products from an Android app, create an Intent that opens a URL. As you configure this intent, pass "com.android.vending" into Intent.setPackage() so that users see your app's details in the Google Play Store app instead of a chooser."
This is the Kotlin code I used to direct users to viewing the app containing the package name com.google.android.apps.maps in Google Play:
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.apps.maps")
setPackage("com.android.vending")
}
startActivity(intent)
I hope that helps someone!
All of the above answers open Google Play in a new view of the same app, if you actually want to open Google Play (or any other app) independently:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
// package name and activity
ComponentName comp = new ComponentName("com.android.vending",
"com.google.android.finsky.activities.LaunchUrlHandlerActivity");
launchIntent.setComponent(comp);
// sample to open facebook app
launchIntent.setData(Uri.parse("market://details?id=com.facebook.katana"));
startActivity(launchIntent);
The important part is that actually opens google play or any other app independently.
Most of what I have seen uses the approach of the other answers and it was not what I needed hopefully this helps somebody.
Regards.
You can check if the Google Play Store app is installed and, if this is the case, you can use the "market://" protocol.
final String my_package_name = "........." // <- HERE YOUR PACKAGE NAME!!
String url = "";
try {
//Check whether Google Play store is installed or not:
this.getPackageManager().getPackageInfo("com.android.vending", 0);
url = "market://details?id=" + my_package_name;
} catch ( final Exception e ) {
url = "https://play.google.com/store/apps/details?id=" + my_package_name;
}
//Open the app page in Google Play store:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
Ready-to-use solution:
public class GoogleServicesUtils {
public static void openAppInGooglePlay(Context context) {
final String appPackageName = context.getPackageName();
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException e) { // if there is no Google Play on device
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
}
Based on Eric's answer.
This link will open the app automatically in market:// if you are on Android and in browser if you are on PC.
https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1