我正在寻找一种方法在设备中搜索所有能够通过操作过滤意图的应用程序" VIEW"和类别" BROWSABLE"?
我找到了以下链接,并学会了如何列出所有意图过滤器,但是如何只列出那些只有上述参数?
Get intent filter for receivers
How to filter specific apps for ACTION_SEND intent (and set a different text for each app)
提前致谢
答案 0 :(得分:11)
此代码应该或多或少地执行您想要的操作。主要问题是,我认为您不会发现任何针对CATEGORY_BROWSABLE
过滤的活动,而不需要特定类型的数据。我在手机上试了一下,直到我在意图上添加setData()
电话后才得到任何有用的东西。
PackageManager manager = getPackageManager();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
// NOTE: Provide some data to help the Intent resolver
intent.setData(Uri.parse("http://www.google.com"));
// Query for all activities that match my filter and request that the filter used
// to match is returned in the ResolveInfo
List<ResolveInfo> infos = manager.queryIntentActivities (intent,
PackageManager.GET_RESOLVED_FILTER);
for (ResolveInfo info : infos) {
ActivityInfo activityInfo = info.activityInfo;
IntentFilter filter = info.filter;
if (filter != null && filter.hasAction(Intent.ACTION_VIEW) &&
filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
// This activity resolves my Intent with the filter I'm looking for
String activityPackageName = activityInfo.packageName;
String activityName = activityInfo.name;
System.out.println("Activity "+activityPackageName + "/" + activityName);
}
}
}