gpt4 book ai didi

android - 有什么方法可以查询特定类型的支持 Intent Filter 的应用程序吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:50:40 25 4
gpt4 key购买 nike

我正在寻找一种方法来在设备中搜索所有能够使用操作“VIEW”和类别“BROWSABLE”过滤 Intent 的应用程序?

我找到了以下链接并了解了如何列出所有 Intent 过滤器,但我如何才能只列出那些只有上述参数的过滤器?

http://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities%28android.content.Intent,%20int%29

Get intent filter for receivers

How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

提前致谢

最佳答案

此代码或多或少应该可以满足您的需求。主要问题是,我认为您不会找到任何过滤 CATEGORY_BROWSABLE 而不需要特定类型的 data 的 Activity 。我在我的手机上试过了,但在我对 Intent 添加 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);
}
}
}

关于android - 有什么方法可以查询特定类型的支持 Intent Filter 的应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11752081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com