In my Android app, I want to prompt the user at some point of time to rate the app in Android market.
Having searched for an approach, I've found some code on this website. This code seems to work very well.
But unfortunately, this code seems to raise a "Forced Close" error message when Android market is not installed on the user's phone. Is there any way to check if Android market is installed and, if not, don't try to execute the code?
The line which raises the error is probably this one as it cannot parse the URI:
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
And, by the way, are there any other things which could be improved in that code?
Edit:
A few years later, I've put all the code into a small library project: AppRater on GitHub
Here's all the code you need, (a conglomeration of Kurt's answer and inferred information, plus the link and the question):
/* This code assumes you are inside an activity */
final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);
if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0)
{
startActivity(rateAppIntent);
}
else
{
/* handle your error case: the device has no way to handle market urls */
}