如何知道在 Intent.ACTION_SEND 中选择了哪个意图? [英] How to know which intent is selected in Intent.ACTION_SEND?

查看:20
本文介绍了如何知道在 Intent.ACTION_SEND 中选择了哪个意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Android Intent.ACTION_SEND 来快速分享一些东西.所以我得到了这样的共享列表:

I want to use Android Intent.ACTION_SEND for quickly sharing something. So I got a sharing list like this:

但我想为每个动作分享不同的内容,例如:

But I want to share different content for each action, such as:

  • 如果通过电子邮件/Gmail 共享,内容应为通过电子邮件共享".

  • If sharing by Email/Gmail, content should be "Share by email".

如果通过 Facebook 分享,内容应为通过 Facebook 分享".

If sharing by Facebook, content should be "Share by Facebook".

那么,可以这样做吗?

推荐答案

您无法获得此类信息.

除非您为活动选择创建自己的对话框实现.

Unless you create your own implementation of the dialog for the activity selection.

要创建这样的对话框,您需要使用 PackageManager 及其 queryIntentActivities() 函数.该函数返回List.

To create such dialog you need to use PackageManager and its queryIntentActivities() function. The function returns List<ResolveInfo>.

ResolveInfo 包含有关活动的一些信息(resolveInfo.activityInfo.packageName),在 PackageManager 的帮助下,您可以获得其他信息(用于在对话框中显示活动) - 应用程序图标可绘制,应用程序标签,......

ResolveInfo contains some information about an activity (resolveInfo.activityInfo.packageName), and with the help of PackageManager you can get other information (useful for displaying the activity in the dialog) - application icon drawable, application label, ... .

在对话框(或样式为对话框的活动中)的列表中显示结果.当一个项目被点击时创建新的 Intent.ACTION_SEND,添加你想要的内容并添加所选活动的包(intent.setPackage(pkgName)).

Display the results in a list in a dialog (or in an activity styled as a dialog). When an item is clicked create new Intent.ACTION_SEND, add the content you want and add the package of the selected activity (intent.setPackage(pkgName)).

这篇关于如何知道在 Intent.ACTION_SEND 中选择了哪个意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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