问题
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_STORAGEorandroid.permission.READ_EXTERNAL_STORAGEpermission in your manifestCheck that the
uriresolves 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