Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val attachmentUris = ArrayList<Uri>().apply {
add(FileProvider.getUriForFile(activity, "gg.mark.provider", File.createTempFile("gg", ".txt", context.cacheDir)))
add(FileProvider.getUriForFile(activity, "gg.mark.provider", File.createTempFile("hello", ".txt", context.cacheDir)))
}
val sendEmailIntent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
type = "text/plain"
// Needed to get file attachments working on older versions of Android
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
putExtra(Intent.EXTRA_EMAIL, EMAIL_RECIPIENTS)
putExtra(Intent.EXTRA_SUBJECT, "With love from mark.gg")
putExtra(Intent.EXTRA_TEXT, "Be the change you want to see in the world.")
putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris)
}
activity.startActivity(sendEmailIntent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.