首页 > 代码库 > Android - 判断intent-filter的特定的action

Android - 判断intent-filter的特定的action

判断intent-filter的特定的action


本文地址:http://blog.csdn.net/caroline_wendy


如果使用startIntent()启动Activity时,如果intent-filter中未包含此action,则会异常崩溃;
在使用时,可以先进行检查:
    // 判断是否安装【健康工具】
    private boolean isInstallChunyuTools() {

        Intent cardioFaceIntent = new Intent(EtonConstants.CHUNYU_CARDIO_FACE_ACTION);
        Intent pedometerIntent = new Intent(EtonConstants.CHUNYU_PEDOMETER_ACTION);

        PackageManager pm = getPackageManager();

        List<ResolveInfo> cardioFaceInfos =
                pm.queryIntentActivities(cardioFaceIntent, PackageManager.GET_RESOLVED_FILTER);
        List<ResolveInfo> pedometerInfos =
                pm.queryIntentActivities(pedometerIntent, PackageManager.GET_RESOLVED_FILTER);

        return cardioFaceInfos.isEmpty() || pedometerInfos.isEmpty();
    }


参考:http://stackoverflow.com/questions/20809237/android-search-installed-package-with-intent-filter

heck out queryIntentActivities()
So you create an intent with the correct filter matching discriminators on it.
Intent intent = new Intent("my_awesome.package.hasa.custom.ACTION!");
intent.addCategory("typingisfunfunfun");
intent.setData(Uri.parse("data://foo/bar"));
PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
if(resolveInfo.isEmpty()) {
  Log.i("NoneResolved", "No Activities");
} else {
  Log.i("Resolved!", "There are activities" + resolveInfos);
}





Android - 判断intent-filter的特定的action