安卓发送邮件用PDF文件 [英] Android send mail with PDF file

查看:433
本文介绍了安卓发送邮件用PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发送位于设备上的文件夹中的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表示块,以确保文件的内容实际上是可读的。

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.

这篇关于安卓发送邮件用PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆