Android send mail with PDF file

2019-03-04 22:07发布

I'm trying to send a PDF file that is located in a folder on the device. The file is selected and sent, but it is empty. Where I'm wrong?

String inviare = n_fr.getText().toString();
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name)+"/"+"Folder_"+anno+"/"+"file_"+inviare+".pdf")); 

            Intent sendEmail= new Intent(Intent.ACTION_SEND);
                   sendEmail.setType("application/pdf");
                   sendEmail.putExtra(Intent.EXTRA_SUBJECT, filename);                         
                   sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(sendEmail, "Invia PDF"));

1条回答
劫难
2楼-- · 2019-03-04 22:31
  • Make sure you've enabled the android.permission.WRITE_EXTERNAL_STORAGE or android.permission.READ_EXTERNAL_STORAGE permission in your manifest

  • Check that the uri resolves to an actual file, and try logging the file content (Log.d) in that block of code, to ensure the file contents are actually readable.

查看更多
登录 后发表回答