我解决了为每个可以处理我的操作的应用程序获取一个意图,然后我根据意图包名称执行一些过滤器(在我的情况下,我检查包是否包含“torrent”字样)。这里的代码:
public Intent generateTorrentIntent(Context context, String action, Intent intent) {
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.size() > 0) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
for (ResolveInfo r : resolveInfo) {
Intent progIntent = (Intent)intent.clone();
String packageName = r.activityInfo.packageName;
progIntent.setPackage(packageName);
if (r.activityInfo.packageName.contains("torrent"))
targetedShareIntents.add(progIntent);
}
if (targetedShareIntents.size() > 0) {
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),
"Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
return chooserIntent;
}
}
return null;
}