Tuesday, 16 October 2018

ShareCompat.IntentBuilder: Intent.data mixed with recipient

I'm using the ShareCompat.IntentBuilder in order to send an email with an attached file.

I have no issue with the attached file except that the uri of the file I want to attach is automatically added to the recipient.

See by yourself:

enter image description here

Here is the code I use to send the email:

val fileUri = FileProvider.getUriForFile(context, context.packageName + ".fileprovider", pdfFile)
val shareIntentBuilder = ShareCompat.IntentBuilder
    .from(this@MyActivity)
    .setType(baseContext.contentResolver.getType(fileUri))
    .setStream(fileUri)
    .setSubject(getString(R.string.app_name))
    .setText("Please find attached ...")
    .setEmailTo(arrayOf("email@gmail.com"))

val shareIntent = shareIntentBuilder.intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
shareIntent.data = fileUri
startActivity(shareIntent)

(I have used this tutorial: https://medium.com/androiddevelopers/sharing-content-between-android-apps-2e6db9d1368b)

Does one of you know what mistake I have done?

Thank you in advance



from ShareCompat.IntentBuilder: Intent.data mixed with recipient

No comments:

Post a Comment