2012-03-28 32 views
0

我正在通過本教程https://developers.google.com/cloud-print/docs/android進行谷歌雲打印。我正在嘗試向我的應用程序添加打印功能。然而,我沒有想法什麼docUri代表/手段/定義。我要打印的文件「/sdcard/StudentLatePass.txt」Android - Eclipse - docUri是什麼意思?

這是我到目前爲止,

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 

回答

2

docUri - 要打印的文檔的URI。

什麼是URI?統一資源標識符(URI)是用於標識名稱或資源的字符串(Wiki URI)。

我認爲,你可以通過設置:

printIntent.setDataAndType(Uri.fromFile(new File("/sdcard/StudentLatePass.txt")), "text/plain"); 
+0

這正是我所需要的。你的回答只是確保我按時上大學! – UPGRAYEDD 2012-03-28 18:27:37

+0

沒問題。希望你喜歡畢業;) – Hayden 2012-03-28 19:17:31

+0

@Hayden這個東西不與我的代碼工作..可能是什麼原因可能的原因?它說我也用pdf試過了無效的內容 – Bhupinder 2013-11-29 11:57:52

0

你閱讀文件?這是您要打印的文檔的URI。

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

它甚至說所以在例如:

在上面的代碼,則更換三個參數如下:

docUri - 文件的URI要打印

docMimeType - 要打印的文檔的MIME類型。我們建議您使用PDF(應用/ PDF)格式

docTitle - 在這裏打印文檔的標題,任意字符串將在GCP管理控制檯打印作業的標題

0

docUri上顯示的是你想要打印的文件的Uri。

String location ="/sdcard/StudentLatePass.txt"; 
File f = new File(location); 
     Uri docUri =Uri.fromFile(f);