Android send mail with PDF file

允我心安 提交于 2019-12-20 05:41:37

问题


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:


  • 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.



来源:https://stackoverflow.com/questions/25351322/android-send-mail-with-pdf-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!