0

I want to send multiple images. I tried setType("image/jpeg") also, I see this question posted in a lot of places, but didn't find correct answer

val emailIntent = Intent(android.content.Intent.ACTION_SEND_MULTIPLE, Uri.parse("mailto:" + context?.resources?.getString(R.string.email)))
emailIntent.setType("application/image")
val uris = ArrayList<Uri>()

for (file in filePaths) {
    val fileIn = File(file)
    val u = Uri.fromFile(fileIn)
    uris.add(u)
}
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject)
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody)
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)

context?.startActivity(Intent.createChooser(emailIntent, "Email:"));
Komal12
  • 3,340
  • 4
  • 16
  • 25
I.S
  • 1,904
  • 2
  • 25
  • 48
  • https://stackoverflow.com/a/14457735/3673259 It said `application/image` instead of `image/jpeg` – Joshua Jul 18 '17 at 06:07
  • @Joshua I tried both application/image and image/jpeg but non of them are working – I.S Jul 18 '17 at 07:30

1 Answers1

0
  • The ACTION_SEND_MULTIPLE Intent doesn't take a data argument. So get rid of the Uri.parse("mailto:... argument in the constructor. Put the email address into EXTRA_EMAIL instead. Note that this extra is holding a string array, not a simple string.
  • The correct type to use is image/jpeg if all of the attachments are JPEGs, otherwise use image/*.
  • Sharing file:// URIs is being a bad Android citizen. It requires the receiving app to hold the storage permission. Use FileProvider instead and don't forget to add the flag FLAG_GRANT_READ_URI_PERMISSION.
cketti
  • 1,277
  • 11
  • 15