Redirecting a user to the Play Store from an Android application

Hello friends, I’m developing an application, I had a requirement to redirect the user to the game in the store from my application, I searched a lot, but did not have time .. the code is below

Button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v_arg) { try { Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/")); startActivity(viewIntent); }catch(Exception e) { Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }); Button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v_arg) { try { Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=com.adeebhat.rabbitsvilla/")); startActivity(viewIntent); }catch(Exception e) { Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }); 
+6
source share
3 answers

More complicated way:

 final String appPackageName = getPackageName(); // package name of the app 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))); } 
+11
source

Remove the slash from url. You have added an additional slash after the package name.

 https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/ 

It should be

 https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla 

Both uri should be

 Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); // Removed slash 

and

 Uri.parse("market://details?id=com.adeebhat.rabbitsvilla")); // Removed slash 
+8
source

You just need to remove the "/" character from the URL

So be it

 https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/ 

to

 https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla 

So finally

 Button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v_arg) { try { Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); startActivity(viewIntent); }catch(Exception e) { Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }); 
+7
source

All Articles