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); } });
source share