1

Ive been using the recommended way to populate an email intent since the early days of Android. This includes recipient, subject, and body text.

On Android 12 however - the recipient field is always left out when doing this, everything else works exactly the same.

Whats is the issue here? Is this a bug in the OS? Im testing with gmail by default, but the same thing applies to other email clients, still only on Android 12.

private fun createIntent(
    metadata: String
): Intent {
    val uri = Uri.parse("mailto:")

    return Intent(ACTION_SENDTO)
        .setData(uri)
        .putExtra(
            EXTRA_EMAIL,
            arrayOf("example@gmail.com") //Ive also tried without arrayOf, no difference.
        )
        .putExtra(
            EXTRA_SUBJECT,
            "Feedback"
        )
        .putExtra(
            EXTRA_TEXT,
            metadata
        )
}
4

1 回答 1

1

似乎与块ACTION_SEND结合使用可以解决问题。selector这适用于所有 API 级别,直到 API 21。我让其他人解释为什么会这样,但重要的是它有效。

private fun createIntent(
    metadata: String
): Intent {
    return Intent(ACTION_SEND)
        .putExtra(
            EXTRA_EMAIL,
            arrayOf(EMAIL)
        )
        .putExtra(
            EXTRA_SUBJECT,
            TITLE
        )
        .putExtra(
            EXTRA_TEXT,
            metadata
        )
        .apply {
            selector = Intent(ACTION_SENDTO).setData(Uri.parse("mailto:"))
        }
}
于 2021-11-01T12:15:28.003 回答