我正在使用带有android项目的google云打印来打印出pdf文件。我将文件存储在项目的assets文件夹中,当我打印时,它会显示“Document missing”。
这是我的代码
public void stevePrint(View view) {
Intent printIntent = new Intent(this, PrintDialogActivity.class);
//Cant find file, why?
File file = new File("/assets/steve.pdf");
printIntent.setDataAndType(Uri.fromFile(file), "document/pdf");
printIntent.putExtra("title", "Steve");
startActivity(printIntent);
Context context = getApplicationContext();
CharSequence text = "Sending to Google Cloud Print";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
感谢任何帮助!
答案 0 :(得分:9)
您似乎使用了错误的MIME类型。它应该是:
printIntent.setDataAndType(Uri.fromFile(file), "application/pdf");
看起来你正在使用PrintDialogActivity,from the Google Cloud Print documentation。确保还为@JavascriptInterface
内的每个方法添加PrintDialogJavaScriptInterface
注释。