I have created a navigation menu in my application where users can use and select the option of rating my app. The problem I am currently having is trying to figure out how to add a link to the rate my app button before I have actually published the app? How do developers add this option to their app before publishing it and what would be the best code to use for this problem?
This is the current code I have added in my MainActivity.java to send the user to rate my app. What changes should I make to this code?
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_thumb:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.mydomain.tapp"));
startActivity(intent);
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
CodePudding user response:
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" this.getPackageName())));
} catch (android.content.ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" this.getPackageName())));
}
CodePudding user response:
/*
* Start with rating the app
* Determine if the Play Store is installed on the device
*
* */
public void rateMyApp()
{
try
{
Intent rateIntent = rateIntentForUrl("market://details");
startActivity(rateIntent);
}
catch (ActivityNotFoundException e)
{
Intent rateIntent = rateIntentForUrl("https://play.google.com/store/apps/details");
startActivity(rateIntent);
}
}
private Intent rateIntentForUrl(String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT >= 21)
{
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
}
else
{
//noinspection deprecation
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
}
intent.addFlags(flags);
return intent;
}
Add this code in the Activity
or Class
from where you would like to call.
Just call rateMyApp()
with user click action