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

前端 未结 2 461

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 );
    }
    

提交回复
热议问题