B4A Library CloudPrint - Library

This library will allow you to add printing capabilities to your apps using CloudPrint.

This is an alternative solution to the one on THIS post.

Requirements:

1- A printer connected to CloudPrint, see the setup instructions HERE.

2- The CloudPrint app installed on your device.

3- Copy the CloudPrint.xml and CloudPrint.jar to your additional libraries directory.

Usage:
B4X:
'Initialize the library
Private print As CloudPrint

print.Initialize

'To print a document do this:
print.SendToCloudPrint("Test file", File.DirDefaultExternal, "Sample_Document.txt")

'To print a website
print.SendWebViewToCloudPrint("My Website", WebView1)

'To see your print queue
print.ShowPrintJobs

That's it!!

NOTES:

* This lib is not compatible with KitKat (KitKat has printing built in but I've been unable to get it to work, stay tuned).

* You CANNOT print documents saved on DirAssets, DirInternal or DirInternalCache.

* Make sure you have the most current CloudPrint app installed.

A sample project is attached.

Thank you.
 

Attachments

  • CloudPrint_Lib_Sample.zip
    10.2 KB · Views: 613
  • CloudPrint_Lib_2.0.zip
    4.2 KB · Views: 665
Last edited:

JohnFGF

New Member
Licensed User
Longtime User
Hi
I have a Samsung Note with Jelly Bean 4.1.2. Cloud Printing has been enabled
When I load this sample and try to print the sample document I get the attached error

Is this Jelly Bean or something else
 

Attachments

  • error.png
    error.png
    76.3 KB · Views: 340

JohnFGF

New Member
Licensed User
Longtime User
Hi
Is it possible to print a letter with a logo ( .jpg or .png) then text on one page.
I have tried to convert the text to html, and Couldprint that using (text\html) and added , and it works ok, but the logo just comes out as a blank square <img src="smiley.gif" alt="Smiley face">
Thanks in advance
John
 

JohnFGF

New Member
Licensed User
Longtime User
Have you installed CloudPrinting app (see step #2)?

Hi

I have installed the CloudPrint App on my phone, it works ok.
When I run the CloudPrint_Sample, it loads OK but I get a Permission denied Error. See attached log file

Hope you can help

Thanks

John



B4X:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


** Activity (main) Resume **


java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SEND flg=0x20001 cmp=com.google.android.apps.cloudprint/.printdialog.CloudPrintLauncherActivity (has clip) (has extras) } from ProcessRecord{434c9c68 18656:njdude.cloudprint.sample/u0a189} (pid=18656, uid=10189) not exported from uid 10211


    at android.os.Parcel.readException(Parcel.java:1425)
    at android.os.Parcel.readException(Parcel.java:1379)
    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1948)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1426)
    at android.app.Activity.startActivityForResult(Activity.java:3428)
    at android.app.Activity.startActivityForResult(Activity.java:3389)
    at android.app.Activity.startActivity(Activity.java:3599)
    at android.app.Activity.startActivity(Activity.java:3567)
    at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:686)
    at njdude.cloudprint.sample.cloudprint._sendtocloudprint(cloudprint.java:61)
    at njdude.cloudprint.sample.cloudprint._sendwebviewtocloudprint(cloudprint.java:80)
    at njdude.cloudprint.sample.main._menuprintwebsite_click(main.java:418)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:157)
    at njdude.cloudprint.sample.main$B4AMenuItemsClickListener.onMenuItemClick(main.java:152)
    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:144)
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
    at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:180)
    at android.widget.AdapterView.performItemClick(AdapterView.java:301)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
    at android.widget.AbsListView$1.run(AbsListView.java:4161)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
 

tdocs2

Well-Known Member
Licensed User
Longtime User
A new version has been attached to the first post (1.2) which fixes the new permissions set to the CloudPrint app.

Greetings and thanks, NJ, for all of your contributions to this forum.

I hope you are able to come to grips with the 4.4 issue related to this lib.

General question:

How much does Google Cloud Print cost? I have seen Google Cloud Drive costs on the Web but not for Print.

Thank you.
 

NJDude

Expert
Licensed User
Longtime User
Google Print it's free since it uses your own printer.

Regarding 4.4, CloudPrint is integrated with the OS so the behavior is different, I haven't found a way to use it yet.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you again, NJ. Your lib really makes it easy to print from B4A apps.

If the Google Print is free, how does Google profit? On the cloud storage, Google provides a free base - I think it is now 15GB?, but then offers paid services for different usage levels. I thought I had read somewhere (or maybe just concluded) that Google Print worked the same way - free up to a point then charge, but I have not been able to find any info on the Web related to this. On the other hand, Google does not state anywhere that the Cloudprint service is free. The app is free and now is integrated into 4.4. (BTW, HP ePrint is also integrated into 4.4.)

I can attest that HP ePrint which I have used from Android devices is free as of now, but of course, HP ePrint only works on HP printers and HP is profiting from the printer and printer supplies sales.

Best regards.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hey, great library. Is there a way to configure a default printer in your app so you don't get the dialog box from cloud print?
 

ValDog

Active Member
Licensed User
Longtime User
As well as I can tell, I have the CloudPrint app (Google) installed, but when I try to "Print document" or "Show print jobs" I get a message telling me that "You don't have the required CloudPrint app installed." ???
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hey, I was looking at the sample again.. and came across a compile error on line 77

print.SendWebViewToCloudPrint(WebView1, "") - error inconvertible types

B4X:
B4A line: 77
print.SendWebViewToCloudPrint(WebView1, \
javac 1.7.0_51
src\njdude\cloudprint\sample\main.java:437: error: inconvertible types
mostCurrent._print._sendwebviewtocloudprint(BA.ObjectToString(mostCurrent._webview1),(anywheresoftware.b4a.objects.WebViewWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.WebViewWrapper(), (android.webkit.WebView)("")));
 
Top