在Android中使用Google云打印

wii*_*eat 2 android google-cloud-print

我正在使用谷歌云打印与Android项目打印出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();
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!

Pau*_*sma 9

您似乎使用了错误的MIME类型.它应该是:

printIntent.setDataAndType(Uri.fromFile(file), "application/pdf");
Run Code Online (Sandbox Code Playgroud)

您似乎正在使用Google Cloud Print文档中的 PrintDialogActivity .确保还@JavascriptInterface为每个方法添加注释PrintDialogJavaScriptInterface.

  • 这应该标记为答案.此外,如果有人碰巧能够运行云打印,但打印按钮将无法正常工作,请确保导入android.webkit.JavascriptInterface; 并添加Paul所述的@JavascriptInterface.我一直在寻求如何解决这个问题几周.这很容易被忽视.非常感谢Paul! (2认同)