Skip to content

Instantly share code, notes, and snippets.

@markcerqueira
Created June 19, 2018 04:55
Show Gist options
  • Save markcerqueira/b8b1d16afd0784dd889896e265245766 to your computer and use it in GitHub Desktop.
Save markcerqueira/b8b1d16afd0784dd889896e265245766 to your computer and use it in GitHub Desktop.
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