Tuesday 2 September 2014

HB Blog 13: Wireless Printing Using Google Cloud Print Integration.

How to add printing functionality to any Android application by integrating with Google Cloud Print?

Note:- The instructions below are for incorporating Google Cloud Print into your app when run on Android 4.3 and below.
When on Android 4.4 and above, your app should instead use the Android Print Framework, which includes support for Google Cloud Print.

It requires to include simple GCP Dialog intent implementation code in the project, start the intent from the code and pass the document to be printed.

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File

Begin by creating two new files in the Android project, print_dialog.xml and PrintDialogActivity.java, as per the above sample code.
Next, add <uses-permission android:name="android.permission.INTERNET" /> to the application manifest.
Finally, add the following intent,
1
2
3
4
Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);
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.
  • docTitle - title of the printed document, arbitrary string that will be shown on the GCP management console as the print job's title

No comments:

Post a Comment