0

我正在通过本教程https://developers.google.com/cloud-print/docs/android进行谷歌云打印。我正在尝试向我的应用程序添加打印功能。但是我不知道 docUri 代表/意味着/定义什么。我正在尝试打印文件“/sdcard/StudentLatePass.txt”

这是我目前所拥有的

public void onClick(View v) {
            //Print using Google Cloud Print
            Intent printIntent = new Intent(StudentActivity.this, PrintDialogActivity.class);
                printIntent.setDataAndType(docUri, "text/plain");
                printIntent.putExtra("title", "Student Late Pass");
                startActivity(printIntent);

            }// onClick
    });// btnPrintSDFile
4

3 回答 3

2

docUri - 要打印的文档的 URI。

什么是 URI?统一资源标识符 (URI) 是用于标识名称或资源 ( Wiki URI )的字符串。

我认为您可以使用以下方法进行设置:

printIntent.setDataAndType(Uri.fromFile(new File("/sdcard/StudentLatePass.txt")), "text/plain");
于 2012-03-28T17:18:15.943 回答
0

你读过文档吗?这是您要打印的文档的 URI。

http://developer.android.com/reference/android/content/Intent.html#setDataAndType(android.net.Uri, java.lang.String)

它甚至在示例中这样说:

在上面的代码中,将三个参数替换如下:

docUri - 要打印的文档的 URI

docMimeType - 要打印的文档的 MIME 类型。我们建议您使用 PDF (application/pdf) 格式

docTitle - 打印文档的标题,将在 GCP 管理控制台上显示为打印作业标题的任意字符串

于 2012-03-28T17:19:32.280 回答
0

docUri 这里是您要打印的文档的 Uri。

String location ="/sdcard/StudentLatePass.txt";
File f = new File(location);
        Uri docUri =Uri.fromFile(f);
于 2012-03-28T17:20:02.377 回答