I try to share a pdf file from android/data/mypackage/files/file.pdf I generate these pdfs also in this app, and when I try to share it, the pdf doesn't appear in on attached files from email, or google drive says something like: "No data to share". Here is my code for sharing pdf:
val aName = intent.getStringExtra("iName")
val file = File(this.getExternalFilesDir(null)?.absolutePath.toString(), "$aName")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, file)
shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
shareIntent.type = "application/pdf"
startActivity(Intent.createChooser(shareIntent, "share.."))
Toast.makeText(this,"$file",Toast.LENGTH_SHORT).show()
FileUriExposedException
, at least on Android 7.0 and higher. UseFileProvider
, please. – BloodthirstyFileProvider
should work back to Android 15 or so. But, you can useUri.forFile()
for files visible on external storage, and that may work as well. – Bloodthirsty