Question

I am working through this tutorial https://developers.google.com/cloud-print/docs/android for google cloud print. I am trying to add a print functionality to my application. However I have NO IDEA what docUri stands for/means/definition. I am trying to print the file "/sdcard/StudentLatePass.txt"

This is what I have so far,

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
Was it helpful?

Solution

docUri - URI of the document to be printed.

What is a URI? A uniform resource identifier (URI) is a string of characters used to identify a name or a resource (Wiki URI).

I think that you can set it using:

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

OTHER TIPS

Did you read the documentation? It's the URI of the doc you want to print.

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

It even says so in the example:

In the code above, replace the three parameters as follows:

docUri - URI of the document to be printed

docMimeType - MIME type of the document to be printed. We recommend that you use PDF (application/pdf) format

docTitle - title of the printed document, arbitrary string that will be shown on the GCP management console as the print job's title

docUri here is the Uri of the document you want to print.

String location ="/sdcard/StudentLatePass.txt";
File f = new File(location);
        Uri docUri =Uri.fromFile(f);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top