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"));
Make sure you've enabled the
android.permission.WRITE_EXTERNAL_STORAGE
orandroid.permission.READ_EXTERNAL_STORAGE
permission in your manifestCheck 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.