问题描述
我的应用程序使用iText库(带有已填写表格的模板PDF)创建了PDF,然后我想将其附加到电子邮件中进行发送.尝试附加文件时,我在Gmail应用中收到错误无法附加空文件
.还尝试过使用HTC电子邮件应用程序和Touchdown电子邮件应用程序-两者都没有附加任何内容且没有错误.
My app creates a PDF using iText library (template PDF with forms which are filled) and I want to then attach it to an email to send. When I try to attach the file I get the error Can't attach empty file
in the Gmail app. Have also tried with the HTC email app and Touchdown email app - both of which just don't attach anything and give no error.
创建PDF:
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
// Fill all PDF forms here (theres quite a few)
stamper.setFormFlattening(true);
stamper.close();
reader.close();
}
尝试附加文件和发送电子邮件:
public void sendMail(){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent .setType("*/*");
emailIntent .putExtra(Intent.EXTRA_EMAIL, "blah@gmail.com");
emailIntent .putExtra(Intent.EXTRA_STREAM, Uri.parse(dest));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
其中 dest
是所讨论文件的路径和文件名.我知道 dest
中的路径和文件名都可以,因为这是用于保存文件的var(我可以在设备和PC上正常查看).
Where dest
is the path and filename of the file in question. I know the path and filename in dest
are ok as this is the var used to save the file (which I can view fine on both the device and on a PC).
Gmail日志猫:
06-26 00:24:48.901 14476-14476/? E/Gmail﹕ Error adding attachment
com.android.mail.utils.b: Cannot attach empty attachment
at com.android.mail.ui.ComposeAttachmentTileGrid.a(SourceFile:62)
at com.android.mail.compose.c.b(SourceFile:1933)
at com.android.mail.compose.c.c(SourceFile:2063)
at com.android.mail.compose.c.a(SourceFile:7992)
at com.android.mail.compose.c.q(SourceFile:759)
at com.android.mail.compose.c.onCreate(SourceFile:4830)
at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:194)
at android.app.Activity.performCreate(Activity.java:5958)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
推荐答案
我遇到了类似的问题.上面的CommonsWare注释解决了!!
I was facing a similar issue. CommonsWare's comment above resolved it.!
创建一个File对象,并使用Uri.fromFile()方法生成一个Uri.
Create a File object and generate a Uri using Uri.fromFile() method.
File file = new File(filePath);
Uri uri = Uri.fromFile(file);
这篇关于Gmail“无法附加空文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!