在Android中发送电子邮件,只选择电子邮件应用,并指定附件mime类型 [英] Send an email in Android selecting only email apps AND specifying attachment mime type

查看:140
本文介绍了在Android中发送电子邮件,只选择电子邮件应用,并指定附件mime类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

1)指定类型为message / rfc822,以便只有电子邮件应用程序才会显示在选择器中。



不方便:我无法使用EXTRA_STREAM和Uri指定我附加的图像的MIME类型。许多接收电子邮件应用程序(Gmail,Android等)将此显示为邮件附加的未知binarublob,不知道如何预览它,并且不知道如何打开它作为附件。



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



不方便:对于发送用户,我无法减少列表用户必须从选择器中选择应用程序以发送电子邮件应用程序,并且我的Android设备中显示了多个应用程序,其中大部分不是电子邮件应用程序,而不是我想要的。



有没有指定它的message / rfc822电子邮件意图AND指定在Intent.EXTRA_STREAM中通过Uri附加的数据的MIME类型?



BTW:我从我自己的ContentProvider提供文件,并且没有调用getType()方法(用于确定文件MIME类型)。查询()方法但不要求文件类型,只显示名称和文件大小。



谢谢

解决方案

android-developer Google Group



如果您愿意滚动自己的对话框,您可以:



步骤1:创建消息/ rfc822 Intent ,就好像你要
以这种方式发送,并使用 PackageManager
queryIntentActivities()找出谁处理它。



步骤2:创建 image / png ,就像你要这样发送
一样,并用 PackageManager queryIntentActivities()
找出谁处理它。



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



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




  • 步骤#4a:如果交集有一个匹配,请跳过此步骤。

  • 步骤#4b:如果交叉点没有匹配,请让用户知道
    您不能发送消息。



步骤5:修改 image / png Intent 从对话框中添加选定的组件
,然后调用 startActivity()



通过在 Intent 中指定组件,它将转到
特定活动。这是正常的选择者
的效果。


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

解决方案

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.

这篇关于在Android中发送电子邮件,只选择电子邮件应用,并指定附件mime类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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