I have files on my phone. I cant send pdf files to Gmail, for a test a created a list with png and pdf files, this files is located in the same folder. But, png files is sended to Gmail, pdf files didnt attachet. Cant understand why its happens
My code:
Intent emailIntent = new Intent(ACTION_SEND_MULTIPLE);
String theme = "Test";
emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType(" message/rfc822");
String to[] = {sendTo};
emailIntent.putExtra(EXTRA_EMAIL, to);
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
emailIntent.putExtra(EXTRA_SUBJECT, theme);
emailIntent.putExtra(EXTRA_TEXT, context.getResources().getString(R.string.text_email_message_body));
try {
((Activity) context).startActivity(Intent.createChooser(emailIntent, "Choose an Email client:"));
}catch (Exception e){
}
UPD:
this code is works on android 9 and 8
UPD:
i have added files like this:
ArrayList<Uri> uris = new ArrayList<>();
File fileIn1 = new File("/storage/emulated/0/TestApp/TestFolder/201123192703_1.png");
Uri u1 = Uri.fromFile(fileIn1);
File fileIn = new File("/storage/emulated/0/TestApp/TestFolder/201124171209_1.pdf");
Uri u = Uri.fromFile(fileIn);
File fileIn2 = new File("/storage/emulated/0/TestApp/TestFolder/201124171209_2.pdf");
Uri u2 = Uri.fromFile(fileIn2);
File fileIn3 = new File("/storage/emulated/0/TestApp/TestFolder/test.pdf");
Uri u3 = Uri.fromFile(fileIn3);
uris.add(u);
uris.add(u2);
uris.add(u1);
uris.add(u3);
file:
Uri
values have been banned since Android 7.0, with an eye towards the sorts of "scoped storage" restrictions that you see in Android 10+. Generally, you will crash with a FileUriExposedException
when you try using a file:
Uri
in an Intent
— I am not certain why you are not crashing here. On the whole, when putting a Uri
in an Intent
, it needs to use a content:
scheme, and the typical way to get one of those for a file is via FileProvider
and getUriForFile()
.