Attaching a PDF to an Email from Android App - File Size is Zero

蓝咒 提交于 2019-12-04 05:40:05
String[] mailto = {""};
                        Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CALC/REPORTS/",pdfname ));
                        Intent emailIntent = new Intent(Intent.ACTION_SEND);
                        emailIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Calc PDF Report");
                        emailIntent.putExtra(Intent.EXTRA_TEXT, ViewAllAccountFragment.selectac+" PDF Report");
                        emailIntent.setType("application/pdf");
                        emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                        startActivity(Intent.createChooser(emailIntent, "Send email using:"));

If your download.pdf file exists in SDCard. So the problem should be get Uri from File. Try this, it works for me.

Uri uri = Uri.fromFile(new File("/sdcard/", "download.pdf"));
Praveenkumar

The same problem happens for me also. I've cleared that using some method from examples. I've already answered a question similar to your query. Maybe that can be helps you.

File externalStorage = Environment.getExternalStorageDirectory();    
String PDFpath = externalStorage.toString();
String pdfpath =path.replace("/mnt","");
Uri uri = Uri.parse(new File("file://" + pdfpath));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!