Skip to content Skip to sidebar Skip to footer

Can I Test To See If An Application Is Avaliable To Handle An Intent, Without Starting It?

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 t

Solution 1:

Use PackageManager and queryIntentActivities() or resolveActivity(). The former will return a List of things that match an Intent to be used with startActivity(). The latter will return null for no matches or an Intent which is the "best match" (which could be the chooser activity if there is more than one match).

Solution 2:

This is a practical example from CommonWare's answer.

String strURL="market://details?id="+thePackage;
Intent the_intent = newIntent(Intent.ACTION_VIEW, Uri.parse(strURL));
the_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
Log.v(TAG,""+_context.getPackageManager().queryIntentActivities(the_intent,Intent.FLAG_ACTIVITY_NEW_TASK));
if (_context.getPackageManager().queryIntentActivities(the_intent,0).size()==0)
{
    String strUrl="https://play.google.com/store/search?c=apps&q="+thePackage;
    the_intent = newIntent(Intent.ACTION_VIEW, Uri.parse(strUrl));
    the_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
}

Post a Comment for "Can I Test To See If An Application Is Avaliable To Handle An Intent, Without Starting It?"