I need to send the document created from my app to only gmail and whatsapp.
for whatsapp I got the working code,
val filelocation = GlobalVariables.getMyFilePath(this, "dummy_file.mem")
val uri = Uri.parse(filelocation.absolutePath)
val whatsappIntent = Intent(Intent.ACTION_SEND)
whatsappIntent.type = "text/plain"
whatsappIntent.setPackage("com.whatsapp")
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "members file list")
whatsappIntent.putExtra(Intent.EXTRA_STREAM, uri)
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
this.startActivity(whatsappIntent)
based on this I just follwed the same for gmail. but the is not getting attached. it toast message file not attached
val email = Intent(Intent.ACTION_SEND)
email.setPackage("com.google.android.gm")
email.putExtra(Intent.EXTRA_EMAIL, arrayOf<String>("[email protected]"))
email.putExtra(Intent.EXTRA_SUBJECT, "members file list")
email.putExtra(Intent.EXTRA_TEXT, message)
email.putExtra(Intent.EXTRA_STREAM, uri)
email.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
email.type = "message/rfc822"
this.startActivity(email)
- how to send attachment to gmail
- how to show only
whatsapp
andgmail
in chooser intent action
how to send attachment to gmail ?
To send files you need some more things,
first Inside
Manifest
->application
add the below snippetthen create a folder
xml
underres
and add this filefile_provider_paths.xml
then on your code add below line instead of
val uri = Uri.parse(filelocation.absolutePath)
Now you can send attachments.
how to show only whatsapp and gmail in chooser intent action ?
refer this link https://stackoverflow.com/a/8550043/8750174