Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created March 13, 2018 06:57
Show Gist options
  • Save shameemreza/7c8ae24689d173131172c09a66d340ba to your computer and use it in GitHub Desktop.
Save shameemreza/7c8ae24689d173131172c09a66d340ba to your computer and use it in GitHub Desktop.
Android Rate me code
private boolean MyStartActivity(Intent aIntent) {
try
{
startActivity(aIntent);
return true;
}
catch (ActivityNotFoundException e)
{
return false;
}
}
//On click event for rate this app button
public void btnRateAppOnClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
//Try Google play
intent.setData(Uri.parse("market://details?id=[Id]"));
if (!MyStartActivity(intent)) {
//Market (Google play) app seems not installed, let's try to open a webbrowser
intent.setData(Uri.parse("https://play.google.com/store/apps/details?[Id]"));
if (!MyStartActivity(intent)) {
//Well if this also fails, we have run out of options, inform the user.
Toast.makeText(this, "Could not open Android market, please install the market app.", Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment