My app has a button that leads (should lead, to be precise 🙂 ) to another application’s page in the GooglePlay. The button’s click reaction is as follows:
public void pressedPurchaseButton(View view)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.infmanrb.multrainer"));
startActivity(browserIntent);
}
However, in emulator, button pressing causes an exception:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.infmanrb.multrainer }
I guess GooglePlay is not installed on Emulator – and that’s the reason. But anyway, what is the correct way to avoid application crashing? Can I check in advance whether the Intent will be handled? Or the only way is to try-catch an exception?
Use a utility method like this :
Pass the intent that you want as action and ofcourse the context reference. If this returns false, this action cannot be handled.
Check this link as well : Check if intent uri is available