在 Android 中发送电子邮件仅选择电子邮件应用程序并指定附件 MIME 类型

发布于 2024-11-04 05:58:49 字数 653 浏览 0 评论 0原文

在我的 Android 应用程序中,我发送附有图像的电子邮件。

使用意图系统发送它,我可以执行以下两件事之一:

1)将类型指定为“message/rfc822”,以便在选择器中仅显示电子邮件应用程序。

不便之处:我无法指定使用 EXTRA_STREAM 和 Uri 附加的图像的 mime 类型。许多接收电子邮件应用程序(Gmail、Android 等)将其显示为附加到邮件的未知 binaru“blob”,不知道如何预览它,也不知道如何将其作为附件打开。

2) 将类型指定为“image/png”。图像已附加,电子邮件客户端(例如 Gmail)可以预览它,并在适当的应用程序中打开附件。

不便之处:对于发送用户,我无法将用户必须在选择器中选择的应用程序列表减少为电子邮件应用程序,并且我的 Android 设备中显示了许多应用程序,其中大多数不是电子邮件应用程序,也不是我想要的应用程序。

是否有办法指定其“message/rfc822”电子邮件意图并指定通过 Intent.EXTRA_STREAM 中的 Uri 附加的数据的 MIME 类型?

顺便说一句:我从我自己的 ContentProvider 提供文件,并且 getType() 方法(用于确定文件 MIME 类型)未被调用。 query() 方法是但不请求文件类型,仅显示名称和文件大小。

谢谢

In my Android App I send email messages with images attached.

Using the Intent system to send it, I can do one of the following two things:

1) Specify type as "message/rfc822" so that ONLY email applications are shown in the Chooser.

Inconvenience: I cannot specify the mime type of the image I attach using EXTRA_STREAM and a Uri. Many receiving email apps (Gmail, Android, etc) show this as an unknown binaru "blob" attached to the message, don't know how to preview it and don't know how to open it as an attachment.

2) Specify the type as (say) "image/png". The image is attached and email clients such as Gmail can preview it, and open the attachment in the appropriate application.

Inconvenience: For the sending user, I cannot reduce the list of apps the user has to select from in the Chooser to email apps, and MANY apps are shown in my Android device, most of which are not email apps and not what I want.

Is there anyway to specify its a "message/rfc822" email Intent AND to specify the MIME type of the data attached via Uri in the Intent.EXTRA_STREAM?

BTW: I am providing the file from my own ContentProvider and the getType() method (used to determine file MIME type) is NOT being called. The query() method is but doesn't request the file type, only display name and file size.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涫野音 2024-11-11 05:58:49

交叉发布我在 android-developer Google Group 上的回答:

如果您愿意推出自己的对话框,您可以:

步骤#1:创建 message/rfc822 Intent,就好像你本来打算
以这种方式发送,并将其与 PackageManager 一起使用
queryIntentActivities() 找出谁处理它。

步骤#2:创建 image/png Intent,就像您要发送一样
这样,并将其与 PackageManagerqueryIntentActivities() 一起使用
找出谁处理它。

步骤#3:计算这两组活动的交集。

步骤 #4:使用它们填充 AlertDialog 供用户选择。

  • 步骤#4a:如果交集有一个匹配项,则跳过此步骤。
  • 步骤#4b:如果交集有零个匹配项,让用户知道
    你无法发送该消息。

步骤#5:修改 image/png Intent 以添加所选组件
从对话框中调用 startActivity()

通过在 Intent 中指定组件,它将转到该组件
特定活动。这实际上是常规选择者的选择
做。

Cross-posting my answer from the android-developer Google Group:

If you are willing to roll your own dialog, you could:

Step #1: Create the message/rfc822 Intent, as if you were going to
send that way, and use it with PackageManager and
queryIntentActivities() to find out who handles it.

Step #2: Create the image/png Intent, as if you were going to send
that way, and use it with PackageManager and queryIntentActivities()
to find out who handles it.

Step #3: Compute the intersection of those two sets of activities.

Step #4: Use those to populate an AlertDialog for the user to choose from.

  • Step #4a: If the intersection has one match, skip this step.
  • Step #4b: If the intersection has zero matches, let the user know
    you can't send the message.

Step #5: Modify the image/png Intent to add the component selected
from the dialog, and call startActivity() on it.

By specifying the component in the Intent, it will go to that
particular activity. This is effectively what the regular chooser
does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文