I almost found many similar links - and none helped
- Gmail is not allowing me to get file from /storage/emulated/0/Android/data/myapppackage/cache/..pdf tried both manually using Gmail and programmatically
- Able to attach if the same file is downloaded to /storage/emulated/0/download/..pdf
CODE -
protected void sendEmail(Context ctx, String filePath){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = Uri.fromfile(new File(filePath)));
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "PDF"));
ctx.startActivity(emailIntent);
}
file_provder.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="/" />
<files-path name="files" path="/" />
</paths>
Tried the following link which almost seems like perfect but doesn't work for me - Attaching cache file to GMail through FileProvider and Intent not working