Android Tutorial [SAMPLE CODE] Print from your Android app

This sample will show you how to print from your smartphone or tablet using Google Cloud Print (login required).

Requirements:

1 - Google GMail account.

2 - The web browser you use MUST allow popups.

3 - Internet connection.

4 - A Printer connected to Google Cloud Print (Follow these instructions to add a Cloud-Ready Printer or a Classic Printer.

5 - Google Chrome installed on your desktop/laptop to do the initial printer setup.

After you have setup your printer, just compile and run the attached project.

This sample project is a simplified version that will allow you to print directly from your app to any printer added to the Cloud Print service, the sample includes some of the types of documents that can be printed, for other types (such as Google Docs) read THIS document (bottom of the page).

Limitations:

* If you use Chrome this sample will work on devices running ICS or higher, also, some devices with custom ROMs might fail too.


I tried to use a WebView but it didn't work, that's why I'm using the browser.

If someone finds a way to do it using a WebView or a better way, please share the knowledge.


Thanks

UPDATE (Nov 26, 2013): There's a better alternative to this method using a library, see THIS thread.
 

Attachments

  • CloudPrintingCode.zip
    57 KB · Views: 2,178
Last edited:

bherrington0421

Member
Licensed User
Longtime User
This is such an awesome tool. Thanks for putting this together. I'm getting this error - has anyone else encountered this? I can't find PrintJob.html anywhere in your project files and the path it's looking for it definitely isn't right. I'm running this in a 4.1 Emulator.
 

Attachments

  • printerror.png
    printerror.png
    45.6 KB · Views: 869

wleupold

Member
Licensed User
Longtime User
Print RTF file to cloud

Hi everybody,
I try to use the cloud print example. In my app I generate an rtf file and want this print out with a cloud printer.
In the example I can use different mimetypes, but there is no doc/file type.
How can I send an rtf file to the cloud an print it?

The example works fine if the rtf file is located on my server:
SendToCloud("url", "http://www.mydomain.com/testfile.rtf")

But what are the Parameters to use for the testfile.rft if located on my device?

Thanks for any help

Werner:BangHead:
 

Geezer

Active Member
Licensed User
Longtime User
Hi NJ,

I'm trying to print using your example as is.

I get a web page saying can't find the file, and nothing prints.

The printer is online and shows OK as a google cloud printer.

Any ideas ?
nofile.png
 

Mike Olmsted

Member
Licensed User
Longtime User
I have Google drive working perfect, my printer is fine, I can print any file. But, I want to print from within my program. Where do I insert my file name to Cloud Print Sample?
B4X:
Sub PrintURLButton_Click   
      'SendToCloud("url", "http://www.google.com/landing/cloudprint/testpage.pdf")
        SendToCloud("url", "file:///" & File.DirDefaultExternal & "/bookmarks.html")       
End Sub
Thanks in advance, Mike
 

Mike Olmsted

Member
Licensed User
Longtime User
That prints the line same as print text button.
I tried url, and text for type
and .pdf, .txt, .html, and .csv as files.
Most common error was cannot fetch the url or would print nothing.
I can print csv to file then convert to pdf , and then print it with no problem. Issue is automating the process.
 

NJDude

Expert
Licensed User
Longtime User
Read the first post, I've added a modified version and I named it: "CloudPrinting_BETA", this new code will require that you enter the MIME type, let me know if that works.

Check the code, I added a couple of notes there.

Thanks
 
Last edited:

Mike Olmsted

Member
Licensed User
Longtime User
Here is my implementation of NJDudes' Cloud printing sample.

1. Print any table
2. Print any query from your database
3. Open drive to see the reports.
4. Backup your data file by sending it to someone.

Wish list.....name the reports before sending so you don't have a dozen reports
named B4A Report.pdf.
 

Attachments

  • BooksUtils.bas
    4.1 KB · Views: 718

GMan

Well-Known Member
Licensed User
Longtime User
Very useful - 'cause the paperless bureau is more far away then before 20 years :cool:
 

luke2012

Well-Known Member
Licensed User
Longtime User
This sample will show you how to print from your smartphone or tablet using Google Cloud Print (login required).

Requirements:

1 - Google GMail account.

2 - The web browser you use MUST allow popups.

3 - Internet connection.

4 - A Printer connected to Google Cloud Print (Follow these instructions to add a Cloud-Ready Printer or a Classic Printer.

5 - Google Chrome installed on your desktop/laptop to do the initial printer setup.

After you have setup your printer, just compile and run the attached project.

This sample project is a simplified version that will allow you to print directly from your app to any printer added to the Cloud Print service, the sample includes some of the types of documents that can be printed, for other types (such as Google Docs) read THIS document (bottom of the page).

Limitations:

* If you use Chrome this sample will work on devices running ICS or higher, also, some devices with custom ROMs might fail too.


I tried to use a WebView but it didn't work, that's why I'm using the browser.

If someone finds a way to do it using a WebView or a better way, please share the knowledge.


Thanks

UPDATE (Nov 26, 2013): There's a better alternative to this method using a library, see THIS thread.


@NJDude outstanding tutorial! There is a way to start a print job progammatically without the browser?
For example :

User tap on a button and the print job is created.
 
Top