根据已安装的 Android 包名称自定义过滤意图选择器 [英] Custom filtering of intent chooser based on installed Android package name

查看:26
本文介绍了根据已安装的 Android 包名称自定义过滤意图选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用内置的意图选择器来显示自定义过滤的应用列表,供用户选择和启动.

I'd like to leverage the built-in intent chooser to display a custom filtered list of apps for user to select from and launch.

我知道如何获取已安装软件包的列表:

I know how to get a list of installed packages:

final Intent myIntent = new Intent(android.content.Intent.ACTION_MAIN);  
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(myIntent, 0);

此时我想根据包名称中包含的特定字符串(或字符串的变体)过滤列表,我也可以弄清楚如何做.

At this point I want to filter the list based on a specific string (or variation of strings) contained within the package name, which I can figure out how to do as well.

但这就是我卡住的地方.据我所知,Intent.createChooser() 只接受一个目标 Intent 作为参数.我希望有一个基于包和类名或其他东西的意图列表的重载.但我没有看到类似的东西.我在某个地方错过了吗?

But here's where I get stuck. As far as I know, Intent.createChooser() takes only a single target Intent as a parameter. I was hoping there was an overload that took a list of intents based on package and class names or something. But I don't see anything like that. Did I miss that somewhere?

所以问题是,这是否可以使用内置选择器来实现,还是我必须使用 AlertDialog Builder 构建自己的选择器?我希望避免后者.

So the question is, is this possible to do with a built-in chooser, or do I have to construct my own with AlertDialog Builder? I'm hoping to avoid the later.

提前致谢.

推荐答案

选择器唯一的一个附加参数是 Intent.EXTRA_INITIAL_INTENTS.它的描述是:

The only one additional parameter for the chooser is Intent.EXTRA_INITIAL_INTENTS. Its description is:

Intent 或 LabeledIntent 对象的 Parcelable[]putExtra(String, Parcelable[]) 附加活动的集合,以放置一个选项列表的前面,当显示给用户时带有 ACTION_CHOOSER.

A Parcelable[] of Intent or LabeledIntent objects as set with putExtra(String, Parcelable[]) of additional activities to place a the front of the list of choices, when shown to the user with a ACTION_CHOOSER.

我没有在 Android 资源中找到任何方法从列表中排除其他活动,因此似乎无法使用选择器执行您想做的事情.

I haven't found any way in Android sources to exclude other activities from the list, so it seems there's no way to do what you want to do using the chooser.

编辑:这很容易找到.只需检查 Choosera> 和 Resolver> 源代码.这些课程相当小.

EDIT: That's really easy to find out. Just check ChooserActivity and ResolverActivity source code. These classes are rather small.

这篇关于根据已安装的 Android 包名称自定义过滤意图选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆