How to click the Android button, then go to the Google Play application

I wonder how to make the android button click and redirect the user to a Google game.

Example: I want to send a user to Android applications (https://play.google.com/store/apps/details?id=com.theopen.android) after the user clicks a button in my activity.

How to do it?

Hi,

+6
source share
5 answers
Button.setOnClickListener(new OnClickListener() { public void onClick(View v) { view=(WebView) findViewById(R.id.w); view.loadUrl("https://play.google.com/store/apps/details?id=com"); } }); 
+3
source
 intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.theopen.android")); startActivity(intent); 

This will open your application in the Play store (Android market)

+39
source

To redirect to a Google game, we need to check if the mobile already has an application for playback, if Google Play should not be opened in the browser.

 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.android.app")); try{ startActivity(intent); } catch(Exception e){ intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.android.app")); } 
+3
source
 Intent launchIntent = getPackageManager().getLaunchIntentForPackage("package name here"); startActivity(launchIntent); 
0
source

See what I have done and it works even if there is no application (like GooglePlay) to accept the first intention. In this case, there is another attempt to open GooglePlay in a web browser - the default should be at least:

  mOkButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.sbm.bc.smartbooksmobile")); // Open precisely @link SmartBooks boolean tryAgain = false; // Flag to denote that normal attempt to launch GooglePlay update failed try { startActivity(intent); } catch(Exception e) { tryAgain = true; } if (!tryAgain) return; // Try to launch GooglePlay with SB in browser ! try { intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.sbm.bc.smartbooksmobile")); startActivity(intent); } catch (Exception e) { mEmailView.setError("Unable to run app update automatically. Please run it from GooglePlay manualy."); mEmailView.requestFocus(View.FOCUS_UP); } // No need to exit the app, as it already exits //finishAffinity(); // this requires API level > 16 //finish(); //System.exit(0); } }); 
0
source

Source: https://habr.com/ru/post/921116/


All Articles