Hi all. It’s all in the title. I would like to send by mail an termsAndConditions.pdf included in the app directory. My below code is for with/without attachment; without attachment the code runs correctly but with attachment, the file is not found (line # 9).
I would very much appreciate if someone could tell me how to correct my code to perform this envoi.
fun Activity.sendMail(emailTo: String, subject: String, message: String, attachment: Boolean) {
val intent = Intent(Intent.ACTION_SEND)
var subjectToUse = subject
if (attachment) {
// send the "termsAndConditions.pdf file"
val fileName = "termsAndConditions.pdf"
val file = File(this.filesDir,fileName)
if (!file.exists()) {
return
}
val uri = Uri.fromFile(file)
intent.putExtra(Intent.EXTRA_STREAM, uri)
} else {
...
subjectToUse =
"$appName v.$versionCode ($versionName) $brand - $sdk - $versCode - $CPU_ABI - $lang_Country"
}
val addressTo = emailTo.split(",".toRegex()).toTypedArray()
intent.putExtra(Intent.EXTRA_EMAIL, addressTo)
intent.putExtra(Intent.EXTRA_SUBJECT, subjectToUse)
intent.putExtra(Intent.EXTRA_TEXT, message)
intent.type = "mail/rfc822"
startActivity(Intent.createChooser(intent, "Send Email using:"))
}
Any help will greatly appreciated.