首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。