我刚刚开始在我正在开发的应用程序中使用文本来进一步了解我的 android 知识。但是,我无法弄清楚如何获取已填充的 pdf,然后使用意图通过电子邮件发送。我一直在到处搜索和研究,但找不到任何东西。有谁知道该怎么做?
在我的 onCreate 之前声明我的文件;
File file = new File(getExternalFilesDir(null),"pvgform.pdf");
这是我的代码的一部分,用于向可填写的 pdf 文本添加信息
OutputStream output = null;
try {
output = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
reader = new PdfReader(getResources().openRawResource(R.raw.form));
} catch (IOException e) {
e.printStackTrace();
}
try {
PdfStamper stamper = new PdfStamper(reader, output);
AcroFields acroFields = stamper.getAcroFields();
acroFields.setField("fullname", editText.getText().toString());
acroFields.setField("agedob", editText2.getText().toString());
acroFields.setField("description", editText3.getText().toString() + editText4.getText().toString() + editText5.getText().toString());
acroFields.setField("duration", editText6.getText().toString());
acroFields.setField("brandname", editText8.getText().toString());
acroFields.setField("genericname", editText9.getText().toString());
stamper.setFormFlattening(true);
stamper.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
reader.close();
这是我对 pdf 表单的电子邮件意图的尝试:
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, "My form");
email.putExtra(Intent.EXTRA_TEXT, "Here is a form");
Log.d("file",file.getAbsolutePath());
Uri uri = Uri.fromFile(file);
email.putExtra(Intent.EXTRA_STREAM,uri);
email.setType("application/pdf");
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
当我运行它时,要发送的电子邮件没有附件。