简体   繁体   English

尝试通过电子邮件发送多个附件时出现 ActivityNotFoundException

[英]ActivityNotFoundException when trying to send multiple attachments via emails

I am receiving this error when trying to send multiple attachment via email:尝试通过电子邮件发送多个附件时收到此错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND_MULTIPLE (has extras) }

I have Gmail and Outlook installed in my Phone.(Samsung device with Android 11).我的手机中安装了 Gmail 和 Outlook。(搭载 Android 11 的三星设备)。 When sending a single attachment I am not facing any issue.发送单个附件时,我没有遇到任何问题。 I am using below intent to share multiple attachment over email我正在使用以下意图通过电子邮件共享多个附件

fun getIntent(
    emailId: Array<String>,
    subject: String,
    body: String,
    attachmentUri: ArrayList<Uri?>
): Intent? {
        val text = ArrayList<String>()
        text.add(body)
      
        return Intent(Intent.ACTION_SEND_MULTIPLE).apply {
            putExtra(Intent.EXTRA_EMAIL, emailId)
            putExtra(Intent.EXTRA_SUBJECT, subject)
            putExtra(
                Intent.EXTRA_TEXT,
                text
            )
            putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUri)
        }}

Above method is called in this way上面的方法就是这样调用的

        val history: ArrayList<Uri?> = getHistory()
        val intent = Utils.getIntent(
            arrayOf(getString(R.string.email_id)),
            subject,
            getString(R.string.body),
            history
        )
        intent?.let {
            try {
                startActivity(it)
            } catch (e: Exception) {
                
            }
        }

String resource:字符串资源:

    <string name="body">\u2022 Information:\n\u0020\u0020\u25E6Name: %s\n\u0020\u0020\u25E6Age: %s\n\u0020\u0020\u25E6%s\n</string>

What am I doing wrong?我究竟做错了什么?

According to the documentation on ACTION_SEND_MULTIPLE , you need to specify the MIME type of your content on your Intent , and you are not doing so.根据ACTION_SEND_MULTIPLE的文档,您需要在Intent上指定内容的 MIME 类型,而您并没有这样做。

Input: getType() is the MIME type of the data being sent.输入:getType() 是正在发送的数据的 MIME 类型。 get*ArrayListExtra can have either a EXTRA_TEXT or EXTRA_STREAM field, containing the data to be sent. get*ArrayListExtra 可以有 EXTRA_TEXT 或 EXTRA_STREAM 字段,包含要发送的数据。 If using EXTRA_TEXT, you can also optionally supply EXTRA_HTML_TEXT for clients to retrieve your text with HTML formatting.如果使用 EXTRA_TEXT,您还可以选择为客户端提供 EXTRA_HTML_TEXT 以检索具有 HTML 格式的文本。

Multiple types are supported, and receivers should handle mixed types whenever possible.支持多种类型,接收者应尽可能处理混合类型。 The right way for the receiver to check them is to use the content resolver on each URI.接收者检查它们的正确方法是在每个 URI 上使用内容解析器。 The intent sender should try to put the most concrete mime type in the intent type, but it can fall back to /* or / as needed.意图发送者应该尝试将最具体的 mime 类型放入意图类型中,但它可以根据需要回退到 /* 或/

eg if you are sending image/jpg and image/jpg, the intent's type can be image/jpg, but if you are sending image/jpg and image/png, then the intent's type should be image/*.例如,如果您要发送 image/jpg 和 image/jpg,则意图的类型可以是 image/jpg,但是如果您要发送的是 image/jpg 和 image/png,则意图的类型应该是 image/*。

However, beyond that, it is entirely possible that a user will not have an app that supports ACTION_SEND_MULTIPLE for your requested MIME type.但是,除此之外,用户完全有可能没有支持ACTION_SEND_MULTIPLE的应用程序用于您请求的 MIME 类型。 Make sure that you do something useful in your catch block for the try around your startActivity() call.确保您在catch块中为围绕startActivity()调用的try做一些有用的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试发送电子邮件会产生ActivityNotFoundException或PermissionDenial - Trying to send emails produces ActivityNotFoundException or PermissionDenial Android:尝试在特定设备上发送MMS时偶尔会遇到ActivityNotFoundException - Android: ActivityNotFoundException occasionally encountered when trying to send MMS on specific devices 尝试启动第二个活动时的ActivityNotFoundException - ActivityNotFoundException when trying to start a second activity 尝试启动 Twitter 应用程序时出现 ActivityNotFoundException - ActivityNotFoundException when trying to start twitter app 尝试从另一个项目调用活动时出现ActivityNotFoundException - ActivityNotFoundException when trying to call an activity from another project 如何使用Android上的gmail客户端API发送带有大附件的电子邮件 - How to send emails with large attachments using gmail client API on Android 无法通过Gmail以编程方式发送带有附件的电子邮件 - Cannot send email with attachments programmatically via Gmail Android 发送带有多个附件的电子邮件问题 - Android send email with multiple attachments issues 如何使用Intent发送多个附件 - How to send multiple attachments using Intent 从电子邮件下载附件时出现JavaMail No Content错误 - JavaMail No Content error when downloading attachments from emails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM