有没有什么办法可以查询意图过滤器的应用程序能够在特定类型的? [英] Is there any way to query an specific type of Intent Filter capable apps?
问题描述
我在寻找一种方式在设备上的所有应用程序至极能够过滤意图与行动查看,搜索类别可浏览?
I'm looking for a way to search in the device all the apps wich are capable to filter Intents with action "VIEW" and category "BROWSABLE"?
我在读下面的链接,并学会了如何列出所有意图过滤器,但我怎么能只列出那些只具有上述参数?
I was reading the following links and learned how to list all Intent Filters, but how can I list only those having only the aforementioned parameters?
<一个href="http://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities%28android.content.Intent,%20int%29" rel="nofollow">http://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities%28android.content.Intent,%20int%29
<一个href="http://stackoverflow.com/questions/9730243/android-how-to-filter-specific-apps-for-action-send-intent">Android - 如何过滤特定的应用程序的ACTION_SEND意图
在此先感谢
推荐答案
这code应该做或多或少你想要什么。主要的问题是,我不认为你会发现,过滤器 CATEGORY_BROWSABLE
不还要求数据特定类型的任何活动。我试了一下我的电话,我没有得到什么有用的东西,直到我说的意图使用setData()
电话。
This code should do more or less what you want. The main problem is that I don't think you will find any activity that filters for CATEGORY_BROWSABLE
without also requiring data of a specific type. I tried it on my phone and I didn't get anything useful until I added the setData()
call on the Intent.
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);
}
}
}
这篇关于有没有什么办法可以查询意图过滤器的应用程序能够在特定类型的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!