Last Updated:

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

I opened the Google Play Store using the following code

 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); 

But it shows me the full kind of action to select the option (browser/game store). I need to open the app in the Play Store directly.


You can do this by using the prefix . market://

 final String appPackageName = getPackageName (); //getPackageName () из объекта Context или Activitytry {startActivity (new Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id =" + appPackageName)));} catch (android.content.ActivityNotFoundException anfe)  {startActivity (новое намерение (Intent.ACTION_VIEW, Uri.parse ("https://play.google.com/store/apps/details?id=" + appPackageName)));} 

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

NOTE: Any app can be registered as being able to handle Uri, if you want to target Google Play, check Berkak's responsemarket://details?id=


Many of the answers here suggest using to open Google Play, but I think that's not enough really: Uri.parse ("market://details? id =" + appPackageName))

Some third-party cation applications can use their own intent filters with a given "market://" scheme, so they can handle the provided Uri instead of Google Play (I experienced this situation with the egSnapPea app). The question is "How do I open the Google Play Store?", so I assume you don't want to open any other app. Also note that, for example, the app rating is only relevant in the GP Store app, etc...

To open Google Play AND GOOGLE PLAY ONLY, I use this method:

 public static void openAppRating(Context context) {//you can also use BuildConfig.APPLICATION_ID String appId = context.getPackageName(); Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?Id=" + appId)); boolean marketFound = false; //find all apps that can handle our rate rateIntent final List otherApps = context.getPackageManager () .queryIntentActivities(rateIntent, 0); for (ResolveInfo otherApp: otherApps) {// looking for Google Play app if (otherApp.activityInfo.applicationInfo.packageName .equals("com.android.vending")) {ActivityInfo otherAppActivity = otherApp.activityInfo; ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName, otherAppActivity.name); //make sure it does NOT open on your activity's stack rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //respawn the task if necessary rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //if Google Play was already open in the search results//this make sure it still navigates to the app page you requested rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //make sure only the Google Play app is allowed //to intercept the intent rateIntent.setComponent(componentName); context.startActivity(rateIntent); marketFound = true; break; }} // if GP is not present on device, open web browser if (! marketFound) { Intent webIntent = new Intent (Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details ?id="+appId)); context.startActivity(webIntent); }}

The thing is, when more apps besides Google Play can open our intent, the app selection dialog is skipped and the GP app is launched directly.

UPDATE: Sometimes it only seems to open the GP app without opening the app profile. As TrevorWiley suggested in his comment, it could solve the problem. (I haven't tested it myself yet...) Intent.FLAG_ACTIVITY_CLEAR_TOP

Cm. This answer is to understand what it does. Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

 
 
 
 

Many of the answers here suggest using to open Google Play, but I think that's not enough really: Uri.parse ("market://details? id = "+ appPackageName))

Some third-party apps may use their own intent filters with a given "market://" scheme, so they can handle the provided Uri instead of Google Play (I experienced this situation with the egSnapPea app). The question is "How do I open the Google Play Store?", so I assume you don't want to open any other app. Also note that, for example, the app rating is only relevant in the GP Store app, etc...

To open Google Play AND GOOGLE PLAY ONLY, I use this method:

 public static void openAppRating(Context context) {//you can also use BuildConfig.APPLICATION_ID String appId = context.getPackageName(); Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?Id=" + appId)); boolean marketFound = false; //find all apps that can handle our rate rateIntent final List otherApps = context.getPackageManager () .queryIntentActivities(rateIntent, 0); for (ResolveInfo otherApp: otherApps) {// looking for Google Play app if (otherApp.activityInfo.applicationInfo.packageName .equals("com.android.vending")) {ActivityInfo otherAppActivity = otherApp.activityInfo; ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName, otherAppActivity.name ); //make sure it does NOT open in your activity's stack rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //respawn the task if necessary rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //if Google Play was already open in the search results//this make sure it still navigates to the app page you requested rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //make sure only the Google Play app is allowed //to intercept the intent rateIntent.setComponent(componentName); context.startActivity(rateIntent); marketFound = true; break; }} // if GP is not present on device, open web browser if (! marketFound) { Intent webIntent = new Intent (Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details ?id="+appId)); context.startActivity(webIntent); }}

The thing is, when more apps besides Google Play can open our intent, the app selection dialog is skipped and the GP app is launched directly.

UPDATE: Sometimes it only seems to open the GP app without opening the app profile. As TrevorWiley suggested in his comment, it could solve the problem. (I haven't tested it myself yet...) Intent.FLAG_ACTIVITY_CLEAR_TOP

Cm. This answer is to understand what it does. Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED


Follow the official Android Developer link as a step-by-step guide, take a look and get the code for your app package from the play store, if it exists, or there are no apps from the play store, then open the app from a web browser.

Official Android Developer Link

https://developer.android.com/ distribute/tools/promotion/linking.html

Link to the app page

From the website: https://play.google.com/store/apps/details?id=

From the Android app: market://подробности ? id =

Link to product list

From the website: https://play.google.com/store/search?q=pub:

From the Android app: market:// search? q = pub:

Link to search result

From the website: https://play.google.com/ store/search? q = & c = apps

From the Android app: market://search? q = & c = apps

 
 

Follow the official Android developer link as a step-by-step guide, take a look at and get the code for your app package from the play store if it exists, or the play store apps don't exist, then open the app from a web browser.

Official Android Developer Link

https://developer.android.com/distribute/tools/promote/linking. html

Link to the app page

From the website: https://play.google .com/store/apps/details? id =

From the Android app: market://details? id =

Link to product list

From the website: https://play. google.com/store/search?q=pub:

From the Android app: market://search? q = pub:

Link to search result

From the website: https://play.google.com/store/search?q=&c=apps

From the Android app: market://search? q = &c=apps


try this

 Intent intent = new Intent (Intent.ACTION_VIEW); intent.setData (Uri.parse ("market://details? id = com.example.android")); startActivity (intent); 

 


try this

 Intent intent = new Intent (Intent  .ACTION_VIEW); intent.setData (Uri.parse ("market://details? Id = com.example.android")); startActivity (intent); 

All of the above answers open Google Play in a new view of the same app if you really want to open Google Play (or any other app) independently:

 Intent launchIntent = getPackageManager(). getLaunchIntentForPackage("com.android.vending");//package name and activityComponentName comp = new component name("com.android.vending", "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); launchIntent.setComponent(comp);//sample to open facebook applaunchIntent.setData(Uri.parse("market://details?id=com.facebook.katana")); startActivity(launchIntent); 

The important part is that it actually opens Google Play or any other app independently.

Most of what I've seen is taking a different approach and that wasn't what I needed, hopefully it will help someone.

Regards.

 

All of the above answers open Google Play in a new form of the same app if you really want to open Google Play (or any other app) independently:

Intent launchIntent = getPackageManager(). getLaunchIntentForPackage("com.android.vending");//package name and activityComponentName comp = new ComponentName("com.android.vending "," com.google.android.finsky.activities.LaunchUrlHandlerActivity"); launchIntent.setComponent(comp);//sample to open facebook applaunchIntent.setData(Uri.parse("market://details?id=com.facebook.katana")); startActivity(launchIntent);

The important part is that it actually opens Google Play or any other app independently.

Most of what I've seen is taking a different answer approach, and that wasn't what I needed, hopefully it will help someone.

Regards.


You can check if the Google Play Store app is installed, and if so, you can use the "market://" protocol.

 final String my_package_name = "........."// 
 

You can check if the Google Play Store is installed, in which case you can use the "market://" protocol.

 final String  my_package_name = "........."// 

Although Eric's answer is correct, and Bergak's code also works. I think it's a more elegant combination of both.

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

By using , you force the device to use the Play Store. If the Play Store is not installed, it will be detected.. setPackage Exception

 
 

Although Eric's answer is correct, and berkak's code also works. I think it's a more elegant combination of both.

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

By using , you force the device to use the Play Store. If the Play Store is not installed, the . setPackage Exception


use market://

 Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id =" + my_packagename));  

 


use market://

 Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id =" + my_packagename)); 

You can:

 final Uri marketUri = Uri.parse ("market://details? id =  "+ packageName); startActivity (new Intent (Intent.ACTION_VIEW, marketUri)); 

get the link here:

You can also try this approach described in the accepted answer to this question: Unable to determine if the Google Play Store is installed on an Android device

 
 

You can:

 final Uri marketUri = Uri.parse ("market://details? id =" + packageName); startActivity (new Intent (Intent.ACTION_VIEW, marketUri)); 

get the link here:

You can also try the approach described in the accepted answer to this question: Unable to determine if the Google Play Store is installed on an Android device


Very late at the party. The official documents are here. And the code described:

 Intent intent = new Intent (Intent.ACTION_VIEW); intent.setData (Uri.parse ("https://play.google.com/store/ apps/details? id = com.example.android ")); intent.setPackage (" com.android.vending "); startActivity (intent); 

As you set up intent, pass in to let users see your app's details in the Google Play Store app instead of the picker. for KOTLIN "com.android.vending" Intent.setPackage ()

 val intent = Intent (Intent.ACTION_VIEW) .apply {data =  Uri.parse ("https://play.google.com/store/apps/details?id=com.example.android") setPackage ("com. android.vending ")} startActivity (intent) 

If you've published an instant app using Google Play Instant, you can launch it as follows:

Intent intent = new Intent(Intent.ACTION_VIEW); Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details").buildUpon(). appendQueryParameter("id", "com.example.android") .appendQueryParameter("launch", "true");//Optional parameters such as referrer are passed to the launched//instant app. You can get these options using //Activity.getIntent(). getdata(). uriBuilder.appendQueryParameter("referrer", "exampleCampaignId"); intent.setData(uriBuilder.build()); intent.setPackage("com.android.vending"); startActivity(intent);

For KOTLIN

 val uriBuilder = Uri.parse("https://play.google.com/store/apps/details") .buildUpon() .appendQueryParameter("id", "com.example.android") .appendQueryParameter("launch" ," true ")//Optional parameters such as referrer are not used by sed in a running//instant application. You can get these options with Activity.intent.data.uriBuilder.appendQueryParameter("referrer", "exampleCampaignId") val intent = Intent(Intent.ACTION_VIEW) .apply { data = uriBuilder.build() setPackage("com.android .vending")} startActivity(intent)

 

 

Very late in the party Official Documents here. And the code described:

 Intent intent = new Intent (Intent.ACTION_VIEW); intent.setData (Uri.parse ("https://play.google.com/store/ apps/details? id = com.example.android ")); intent.setPackage (" com.android.vending "); startActivity (intent); 

As you set up intent, pass in to let users see your app's details in the Google Play Store app instead of the picker. for KOTLIN "com.android.vending" Intent.setPackage ()

val intent = Intent(Intent.ACTION_VIEW) .apply { data = Uri.parse("https://play.google.com/store/apps/details?id=com.example.android") setPackage("com.android .vending")} startActivity(intent)

If you've published an instant app using Google Play Instant, you can launch it as follows:

 Intent intent = new Intent(Intent.ACTION_VIEW); Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details") .buildUpon() .appendQuery Parameter("id", "com.example.android") .appendQueryParameter( "launch", "true");//Optional parameters such as a referrer are passed to the //instant app that is launched. You can get these options with //Activity.getIntent(). Getdata(). UriBuilder. appendQueryParameter("referrer", "exampleCampaignId"); intent.setData(uriBuilder.build()); intent.setPackage("com.android.vending"); startActivity(intent);

For KOTLIN

 val uriBuilder = Uri.parse("https://play.google.com/store/apps/details") .buildUpon() .appendQueryParameter("id", "com.example.android") .appendQueryParameter("launch" , "true")//Optional parameters such as referrer are passed to the running//instant app. You can get these options with Activity.intent.data.uriBuilder.appendQueryParameter("referrer", "exampleCampaignId") val intent = Intent(Intent.ACTION_VIEW) .apply { data = uriBuilder.build() setPackage("com.android .vending")} startActivity(intent)

As official documentation, use instead of , this combines Eric's response and M3-n50 with code reuse (don't repeat yourself): https:// market://

Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()) ); try {startActivity(new Intent(intent).setPackage("com.android.vending"));} catch(android.content.ActivityNotFoundException) {startActivity(intent);}

It tries to open the GPlay application if it exists and reverts to the default values.

 
 
 

As the official documents used instead of , it combines Eric's response and M3-n50 with code reuse (don't repeat) : https:// market://

 Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName())); try {startActivity(new Intent(intent).setPackage("com.android.vending"));} catch(android.content.ActivityNotFoundException) {startActivity(intent);}

It tries to open the GPlay application if it exists and reverts to the default values.


Kotlin may refer to:

Extension:

 fun Activity.openAppInGooglePlay () {val appId = BuildConfig.APPLICATION_IDпопробуйте {this.  startActivity (Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id = $ appId")))} catch (anfe: ActivityNotFoundException) {this.startActivity (Intent (Intent.ACTION_VIEW, Uri.parse ("  https://play.google.com/store/apps/details?id=$appId ")))}} 

Method:

 fun openAppInGooglePlay (activity: Activity) {val appId = BuildConfig.APPLICATION_ID try {activity.startActivity (Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id = $ appId ")))} catch (anfe: ActivityNotFoundException) {activity.startActivity (Intent (Intent.ACTION_VIEW, Uri.parse (" https://play.google. com/store/apps/details? id = $ appId ")))}} 

 

 
 
 

Kotlin may refer to:

Extension:

fun Activity.openAppInGooglePlay() { val appId = BuildConfig.APPLICATION_IDtry { this.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))} catch(anfe: ActivityNotFoundException) {this.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appId")))}}

Method:

 fun openAppInGooglePlay (activity: Activity) {val  appId = BuildConfig.APPLICATION_ID попробуйте {activity.startActivity (Intent (Intent.ACTION_VIEW, Uri.parse ("market://details? id = $ appId")))} catch (anfe: ActivityNotFoundException) {activity.startActivity (Intent (  Intent.ACTION_VIEW, Uri.parse ("https://play.google.com/store/apps/details?id=$appId")))}} 

Ready-to-use solution n:

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 device doesn't have Google Play context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details ?id="+appPackageName))); }}}

Based on Eric's response.

 
 
 

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 device doesn't have Google Play context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details ?id="+appPackageName))); }}}

Based on Eric's response.


Kotlin

 fun openAppInPlayStore(appPackageName: String) { try { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?Id=$appPackageName")))} catch(Exception: android.content.ActivityNotFoundException) { startActivity (Intent (Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")) )}}

 

 
 
 
 

Kotlin

 fun openAppInPlayStore (appPackageName: String) {попробуйте {startActivity (Intent (Intent.ACTION_VIEW, Uri. parse ("market://details? id = $ appPackageName")))} catch (исключение: android.content.ActivityNotFoundException) {startActivity (Intent (Intent.ACTION_VIEW, Uri.parse ("https://play.google.  com/store/apps/details? id = $ appPackageName ")))}} 

If you want to open the Google Play Store from your app, use this command directly: , it will open your app's Google Play Store pages. market://details? Gotohome = com.yourAppName

  • Internet: http://play.google.com/store/apps/details?id=
  • Appendix: market:// more? id =

Show all apps from a specific publisher

  • Internet: http://play.google.com/store/ search? q = pub:
  • App: market://search? q = pub:

Find apps that use a query in the title or description

  • Internet: http://play.google.com/store/search?q=
  • Appendix: market://search ? q =

Reference: https://tricklio.com/market-details-gotohome-1/

 
 
 
 

If you want to open the Google Play Store from your app, use this command directly: , your app's pages in the Google Play Store will open. market://details? gotohome = com.yourAppName

  • Internet: http://play.google.com/store/apps/details?id=
  • Appendix: market://details? id =

Show all apps from a specific publisher

  • Internet : http://play.google.com/store/search?q=pub:
  • Appendix: market://search? q = pub:

Find apps that use a query in the title or description

  • Internet: http://play.google.com/store/search?q=
  • Appendix: market://search? q =

Reference: https://tricklio.com/market-details-gotohome-1/


Here's the latest code from the above answers that first tries to open the app using the Google Play store app and in particular the Play Store, if it fails, it will start viewing the actions using the web version: Credits for @Eric, @Jonathan Caballero

 public void goToPlayStore() { String playStoreMarketUrl = "market://details? id =" ; String playStoreWebUrl = "https://play.google.com/store/apps/details?id="; The line packageName = getActivity(). GetPackageName(); try {Intent intent = getActivity() .getPackageManager() .getLaunchIntentForPackage("com.android.vending"); if (intent != null) { ComponentName androidComponent = new ComponentName("com.android.vending", "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); intent.setComponent(androidComponent); intent.setData(Uri.parse(playStoreMarketUrl + packageName)); } else { intent = new intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName)); } startActivity(intent); } catch(ActivityNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri. parse(playStoreWebUrl + packageName)); startActivity(intent); }}

 

 
 

Here's the latest code from the above answers that first tries to open the app using the Google Play store app and specifically the play store, in case of failure it will start viewing the actions using the web version: Credits for @Eric, @Jonathan Caballero

 public void goToPlayStore() { String playStoreMarketUrl = "market://details?id="; String playStoreWebUrl = "https://play.google.com/store/apps/details?id="; The line packageName = getActivity(). GetPackageName(); try {Intent intent = getActivity() .getPackageManager() .getLaunchIntentForPackage("com.android.vending"); if (intent != null) { ComponentName androidComponent = new ComponentName("com.android.vending", "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); intent.setComponent(androidComponent); intent.setData(Uri.parse(playStoreMarketUrl + packageName)); } else { intent = new intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName)); } startActivity(intent); } catch (ActivityNotFoundException e) { intent intent = new intent(intent.ACTION_VIEW, Uri.parse(playStoreWebUrl + packageName)); startActivity(intent); }}

Some of the answers to this question are outdated.

What worked for me (in 2020) was an explicit indication of the intention to skip the picker and directly open the Play Store app at this link:

» If you want to link to your products from your Android app, create an Intent that opens the URL. When you configure this intent, pass com.android.vending to the Intent.setPackage () so that users see information about your app in the Google Play App Store instead of the picker. «

This is the Kotlin code I used to direct users to view an app that contains 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) 

Hope this helps someone!

iv>
 
 

Some of the answers to this question are outdated.

What worked for me (in 2020) was an explicit indication of the intention to skip the picker 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 the URL. When you configure this intent, pass com.android.vending to the Intent.setPackage() so that users see yourapp details in the Google Play Store app instead of the picker. «

This is the Kotlin code I used to direct users to view an app that contains the package name com.google.android.apps.maps on 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) 

Hope this helps someone!


 public void launchPlayStore(Context context, String packageName) { Intent intent = null; try { intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=" + packageName)); context.startActivity(intent);} catch(android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id= " + packageName)));}}

 

 
 

public void launchPlayStore(Context context, String packageName) { Intent = null; try { intent = new intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id="+packageName)); context.startActivity(intent); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName))); }}

My kotlin extension function for this purpose

 fun Context.canPerformIntent (intent: Intent): Boolean {val mgr = this.packageManager val list = mgr.queryIntentActivities (intent, PackageManager.MATCH_DEFAULT_ONLY) return list.size> 0} 

And in your activity

 val uri = if (canPerformIntent (Intent (Intent.ACTION_VIEW, Uri.parse ("market://"))  )) {Uri.parse ("market://details? Id =" + appPackageName)} else {Uri.parse ("https://play.google.com/store/apps/details?id=" + appPackageName)  } startActivity (Intent (Intent.ACTION_VIEW, uri)) 

 

 
 
 

My kotlin extension function for this purpose

 fun Context.canPerformIntent (intent: Intent): Boolean {val mgr = this.packageManager val list = mgr.queryIntentActivities (intent, PackageManager.MATCH_DEFAULT_ONLY) return list.size>  0} 

And in your activity

val uri = if (canPerformIntent (Intent (Intent.ACTION_VIEW, Uri.parse("market://")))) {Uri.parse("market://details?id=" + appPackageName)} else {Uri. parse("https://play.google.com/store/apps/details?id="+appPackageName)} startActivity(Intent(Intent.ACTION_VIEW,uri))

This link will automatically open the app on market:// if you're running android and in a browser if you're on a PC.

 https://play.app.goo.gl/?link=https://play.google  .com/store/apps/details? id = com.app.id & ddl = 1 & pcampaignid = web_ddl_1 

 

 
 
 
 

This link will automatically open the app in Market:// if you're using Android, and in a browser if you're on a PC.

 https://play.  app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1 

I combined both Berkak and Stefano Munarini, a response to creating a hybrid solution that handles both the Evaluate this application scenario and the Show More Applications scenario.

Use

  • To open a publisher's profile
 @OnClick (R.id.ll_more_apps) public void showMoreApps () {openPlayStore (true, "Hitesh Sahu");  } 
  • Open your app's page in the PlayStore
 @OnClick (R.id.ll_rate_this_app) public void openAppInPlayStore () {openPlayStore (false, "");} 

 

 

I combined both Berťák and Stefano Munarini to create a hybrid solution that handles both. Rate this app and show more apps.

/** * This method checks if GooglePlay is installed on the device or not and handles accordingly * Intents to view app rating or publisher profile * * 

@param showPublisherProfile pass true if you want to open the publisher page, else pass false to open the page APp * @param publisherID pass Dev ID if you passed PublisherProfile true */ public void openPlayStore ( boolean showPublisherProfile, String publisherID) {//Handling errors if (publis herID == null || ! publisherID.isEmpty ()) { publisherID = ""; //Write and continue Log.w("openPlayStore method", "publisherID is invalid"); } Intent openPlayStoreIntent; boolean isGooglePlayInstalled = false; if (showPublisherProfile) {//Open publisher profile in PlayStore openPlayStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:" + publisherID)); } else {//Open this app in PlayStore openPlayStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details? id=" + getPackageName ())); }//find all apps that can handle openPlayStoreIntent final List otherApps = getPackageManager () .queryIntentActivities(openPlayStoreIntent, 0); for (ResolveInfo otherApp: otherApps) {// looking for Google Play app if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {ActivityInfo otherAppActivity = otherApp. activityInfo; ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName, otherAppActivity.name); //make sure it does NOT open in your activity's stack openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //recreate the task if necessary openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //if Google Play was already open in the search results //this make sure it still navigates to the app page you requested openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //make sure only the Google Play app is allowed //to intercept the intent openPlayStoreIntent.setComponent(componentName); startActivity(openPlayStoreIntent); isGooglePlayInstalled = true; break; }}//if Google Play is not installed on the device, open a web browser if (! isGooglePlayInstalled) { Intent webIntent; if (showPublisherProfile) { // Open publisher profile in web browser webIntent = new Intent (Intent.ACTION_VIEW, Uri.parse ("http://play.google.com/store/search?q=pub:" + getPackageName ( ) )); } else {//Open this app in a web browser webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())) ) ; } startActivity(webIntent); }}

Use

  • To open a publisher's profile
 @OnClick (R.id.ll_more_apps) public void showMoreApps () {openPlayStore (true, "Hitesh Sahu");  } 
  • Open your app's page in the PlayStore
 @OnClick (R.id.ll_rate_this_app) public void openAppInPlayStore () {openPlayStore (false, "");} 

Folks, don't forget that you can get more out of it. I mean, for example, UTM tracking. https://developers.google.com/analytics/devguides/collection/android/v4/campaigns

public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free"; public static end string APP_STORE_URI="market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin"; public static end string APP_STORE_GENERIC_URI="https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin"; try {startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, APP_STORE_URI, MODULE_ICON_PACK_FREE), getPackage)(Intent.FLAG_ACTIVITY_CLEAR_TOP));} catch(android.content.ActivityNotFoundException anfe) { startActivity( new intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, APP_STORE_GENERIC_URI) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));}

 


Folks, don't forget that you can get more out of it. I mean, for example, UTM tracking. https://developers.google.com/analytics/devguides/collection/android/v4/campaigns

public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free"; public static end string APP_STORE_URI="market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin"; public static end string APP_STORE_GENERIC_URI="https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin"; try { startActivity (new Intent (Intent.ACTION_VIEW, Uri.parse (String.format (Locale.US, APP_STORE_URI, MODULE_ICON_PACK_FREE), getPackage) (Intent.FLAG_ACTIVITY_CLEAR_TOP)); } catch (android.content.ActivityNotFoundException anfe) { startActivity ( new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, APP_STORE_GENERIC_URI), MODULEFREEN_Pame).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));}

Version of the basin with backup and current syntax

 fun openAppInPlayStore() { val uri = Uri.parse("market://details? id=" + context.packageName) val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri ) var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent )} catch (e: ActivityNotFoundException) { val intent = Intent (Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName)) startActivity( context, intent, null)}}

 

Version of the basin with rollback and current syntax

 fun openAppInPlayStore() { val uri = Uri.parse("market://details? id=" + context.packageName) val goToMa rketIntent = Intent(Intent.ACTION_VIEW, uri) var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NEW_TASK flags = if (Build.VERSIONflags {FACTIVITY_INDOWS) or Intent_flags_Intent_Flags. FLAG_ACTIVITY_CLEAR_TASK} goToMarketIntent.addFlags(flags) try { startActivity (context, goToMarketIntent, null)} catch (e: ActivityNotFoundException) { val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/ store/apps/details?id="+ context.packageName)) startActivity(context, intent, null)}}