Specifically, I'm trying to figure out if there is an application to handle the market intent, but I'd like a general case solution.
I know if you do something like this, you can tell if there is an application available to handle the intent. I'm trying to do something that doesn't actually launch the intent. Any ideas on what I might do?
try
{
String strURL="market://details?id="+thePackage;
Intent the_intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
the_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(the_intent)
}
catch (ActivityNotFoundException e)
{
String strUrl="https://play.google.com/store/search?c=apps&q="+thePackage;
Intent the_intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUrl));
the_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(the_intent)
}
What I want is a solution that doesn't involve actually starting the activity. There's a few reasons why I want to do this, but I imagine I'm not the only one to have thought of a reason for this, it seems like there must be a way...
Use
PackageManager
andqueryIntentActivities()
orresolveActivity()
. The former will return aList
of things that match anIntent
to be used withstartActivity()
. The latter will returnnull
for no matches or anIntent
which is the "best match" (which could be the chooser activity if there is more than one match).This is a practical example from CommonWare's answer.