在 Android 中发送电子邮件仅选择电子邮件应用程序并指定附件 MIME 类型
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
交叉发布我在 android-developer Google Group 上的回答:
如果您愿意推出自己的对话框,您可以:
步骤#1:创建
message/rfc822
Intent
,就好像你本来打算以这种方式发送,并将其与
PackageManager
一起使用queryIntentActivities()
找出谁处理它。步骤#2:创建
image/png
Intent
,就像您要发送一样这样,并将其与
PackageManager
和queryIntentActivities()
一起使用找出谁处理它。
步骤#3:计算这两组活动的交集。
步骤 #4:使用它们填充
AlertDialog
供用户选择。你无法发送该消息。
步骤#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 tosend that way, and use it with
PackageManager
andqueryIntentActivities()
to find out who handles it.Step #2: Create the
image/png
Intent
, as if you were going to sendthat way, and use it with
PackageManager
andqueryIntentActivities()
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.you can't send the message.
Step #5: Modify the
image/png
Intent
to add the component selectedfrom the dialog, and call
startActivity()
on it.By specifying the component in the
Intent
, it will go to thatparticular activity. This is effectively what the regular chooser
does.