首页 > 解决方案 > Android 10+ pdf doesnt send to Gmail

问题描述

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);

标签: androidgmailandroid-11

解决方案


Replace emailIntent.setType(" message/rfc822"); with emailIntent.setType("application/pdf")


推荐阅读