open link of google play store in mobile version android

AndroidGoogle Play

Android Problem Overview


I have link of my other apps in my latest app, and I open them in that way.

Uri uri = Uri.parse("url");
Intent intent = new Intent (Intent.ACTION_VIEW, uri); 
startActivity(intent);

this codes opens the browser version of google play store.

When trying to open from my phone, the phone prompts if I want to use a browser or google play and if I choose the second one it opens the mobile version of google play store.

Can you tell me how can this happen at once? I mean not ask me but directly open the mobile version of google play, the one that I see while open it directly from phone.

Android Solutions


Solution 1 - Android

You'll want to use the specified market protocol:

final String appPackageName = "com.example"; // Can also use getPackageName(), as below
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));

Keep in mind, this will crash on any device that does not have the Market installed (the emulator, for example). Hence, I would suggest something like:

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("http://play.google.com/store/apps/details?id=" + appPackageName)));
}

While using getPackageName() from Context or subclass thereof for consistency (thanks @cprcrack!). You can find more on Market Intents here: link.

Solution 2 - Android

Below code may helps you for display application link of google play sore in mobile version.

For Application link :

Uri uri = Uri.parse("market://details?id=" + mContext.getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
			 
  try {
    	startActivity(myAppLinkToMarket);

      } catch (ActivityNotFoundException e) {
			    	
    	//the device hasn't installed Google Play
        Toast.makeText(Setting.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();
	          }

For Developer link :

Uri uri = Uri.parse("market://search?q=pub:" + YourDeveloperName);
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
	 
		    try {
		    	
		    	startActivity(myAppLinkToMarket);
		        
		    } catch (ActivityNotFoundException e) {
		    	
		    	//the device hasn't installed Google Play
		        Toast.makeText(Settings.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();
		        
		    } 

Solution 3 - Android

You can use Android Intents library for opening your application page at Google Play like that:

Intent intent = IntentUtils.openPlayStore(getApplicationContext());
startActivity(intent);

Solution 4 - Android

Solution 5 - Android

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

Solution 6 - Android

Open app page on Google Play:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionghostriderView Question on Stackoverflow
Solution 1 - AndroidCatView Answer on Stackoverflow
Solution 2 - AndroidChirag GhoriView Answer on Stackoverflow
Solution 3 - AndroidDmitriy TarasovView Answer on Stackoverflow
Solution 4 - AndroidDenis GladkiyView Answer on Stackoverflow
Solution 5 - AndroidPaolo RovelliView Answer on Stackoverflow
Solution 6 - Androiduser3150090View Answer on Stackoverflow