意向选择器基于Android的安装包名称自定义筛选 [英] Custom filtering of intent chooser based on installed Android package name

查看:122
本文介绍了意向选择器基于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()只需要一个目标意图作为参数。我希望有这花了基于组件和类名或东西意图列表的重载。但我没有看到这样的事情。我错过了什么地方?

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生成器?我希望,以避免以后。

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:

一个Parcelable [意图或LabeledIntent对象]根据与putExtra(字符串,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.

我还没有发现任何方式的Andr​​oid源排除列表中的其他活动,因此它似乎没有办法做你想要使用选配的事情。

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.

修改:这是很容易找到的。只是检查<一href="https://github.com/android/platform_frameworks_base/blob/8d21bdb90573ec48491c44eca312c162e262298d/core/java/com/android/internal/app/ChooserActivity.java">ChooserActivity和<一href="https://github.com/android/platform_frameworks_base/blob/8d21bdb90573ec48491c44eca312c162e262298d/core/java/com/android/internal/app/ResolverActivity.java">ResolverActivity来源$ C ​​$ C。这些类是相当小的。

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

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

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