Android Question HP ePrint needed - Please help

MitchBu

Well-Known Member
Licensed User
Longtime User
I am trying to come up with an app that prints over WiFi to an HP ePrint printer.

I have tried to apply the method posted by Erel here
https://www.b4x.com/android/forum/threads/hp-eprint-interface-intent.28221/

But all I get is a MsgBox with
----
Unfortunately, HP ePrint has stopped
Report OK
----

I routinely print to the same printer from the same title iOS app I already created in another tool, and what happens is, the printer "wakes up" and I never saw the same kind of dialog.

Something seems to be missing in the code to bring the printer up :

B4X:
Dim i As Intent
i.Initialize("org.androidprinting.intent.action.PRINT", "file://" & File.Combine(Dir, FileName)) 'make sure that the file is in the external storage
i.SetType("text/plain")
StartActivity(i)

I would appreciate some help in that matter. If I cannot print, this is a definite show stopper:(
 

MitchBu

Well-Known Member
Licensed User
Longtime User
OK. It appears the basic HP plugin did not work. Continuing investigations.

So far the HP all in one app does print.

There was nothing in the log pane of the IDE, though. Unless there are other logs I do not know how to access yet (very possible)...
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
In the bottom of the logs window you have a checkbox to filter the logs, thus showing only B4X related logs, unchecking it will show you ALL the system logs...

PS. Been here for about a year, I like it very much
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
Unfiltered logs don't show more information :(

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

The Msgbox must be coming from the driver. I will try to reinstall all HP stuff and see if that fixes it.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I did verify that cloud printing works fine on the device, by printing from Chrome.


I have implemented the methods you posted at https://www.b4x.com/android/forum/threads/android-printing-framework.38796/page-2
CreatePrinterAttributes and CreateWebPrintJob

It does trigger the cloud print just fine, then I get the messages :

Preparing preview (spinner)
The printer is not available

Then the preview appears, and when I confirm by pressing on the printer icon on the upper right, the document actually prints.

The puzzling thing is that message saying the printer is not available.

But in the end, it does print. Thank you Erel :)
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
Now, since I must go through a WebView, I will need to generate a picture to print with precision.

I looked at the SimpleDrawFunctions SourceCode example. If I can use the same kind of commands to draw to a picture, I can probably create a good printing document.

But I looked at https://www.b4x.com/android/help/core.html#top and I don't find the graphic commands such as drawline, drawrect, drawcircle, darwbitmap, Drawtext...

So my basic questions are :
- Is possible to create a picture and draw to it instead of a view ?
- Where can I find the corresponding set of commands and properties ?
- How will I save the picture to disk to use it in WebView ?
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
OK. Since apparently it is not possible to control margins with cloud printing, I tried to go back to this way.

Unfortunately, I cannot find back my previous project, so I tried this in a button :

B4X:
File.WriteString(File.DirRootExternal, "String.txt", _
        "This is some string" & CRLF & "and this is another one.")
        Msgbox(File.ReadString(File.DirRootExternal, "String.txt"), "")
Dim i As Intent
i.Initialize("org.androidprinting.intent.action.PRINT", "file://" & File.Combine(File.DirRootExternal, "String.txt")) 'make sure that the file is in the external storage
i.SetType("text/plain")
StartActivity(i)

It triggers the error :

Error occurred on line: 86 (Main)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=org.androidprinting.intent.action.PRINT dat=file:///storage/emulated/0/String.txt typ=text/plain flg=0x20000 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3954)
at android.app.Activity.startActivityForResult(Activity.java:3901)
at android.app.Activity.startActivity(Activity.java:4225)
at android.app.Activity.startActivity(Activity.java:4193)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:698)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5214)
at android.view.View$PerformClick.run(View.java:20978)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 
Upvote 0
Top