安卓发送邮件用PDF文件发送邮件、文件、PDF

2023-09-03 22:37:18 作者:梦醒、一切成空

我要发送位于设备上的文件夹中的PDF文件。该文件被选择和发送的,但它是空的。我哪里错了?

 字符串inviare = n_fr.getText()的toString()。
开放的我们的uri = Uri.fromFile(新文件(Environment.getExternalStorageDirectory()的getString(R.string.app_name)+/+文件夹_+安诺+/+文件_+ inviare +PDF));

            意图sendEmail =新的意图(Intent.ACTION_SEND);
                   sendEmail.setType(应用程序/ PDF格式);
                   sendEmail.putExtra(Intent.EXTRA_SUBJECT,文件名);
                   sendEmail.putExtra(Intent.EXTRA_STREAM,URI);
            startActivity(Intent.createChooser(sendEmail,Invia PDF));
 

解决方案

请确保您已启用的 android.permission.WRITE_EXTERNAL_STORAG​​E android.permission.READ_EXTERNAL_STORAG​​E 在你的清单许可

检查 URI 解析为一个实际的文件,并尝试登录文件内容( Log.d )在code表示块,以确保文件的内容实际上是可读的。

PDF文件如何通过电子邮件发送

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