Can I test to see if an application is avaliable to handle an intent, without starting it?

前端 未结 2 462

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 lik

相关标签:
2条回答
  • 2021-01-14 12:15

    This is a practical example from CommonWare's answer.

    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 );
    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 = new Intent(Intent.ACTION_VIEW, Uri.parse(strUrl));
        the_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
    }
    
    0 讨论(0)
  • 2021-01-14 12:26

    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).

    0 讨论(0)
提交回复
热议问题