Android Question android.support.v4.print.PrintHelper ClassNotFoundException

MitchBu

Well-Known Member
Licensed User
Longtime User
I have a working example of printing from a WebView.

I copied it's methods to my app, and made sure to copy the content of #Region ActivityAttributes.

B4X:
Sub PrintBitmap (mybmp As Bitmap)
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim photoPrinter As JavaObject
   photoPrinter.InitializeNewInstance("android.support.v4.print.PrintHelper", Array(ctxt))
   If photoPrinter.RunMethod("systemSupportsPrint", Null) = True Then
     'FIT = 1, FILL = 2
     photoPrinter.RunMethod("setScaleMode", Array(1))
     photoPrinter.RunMethod("printBitmap", Array("Printer Job Name", _
       mybmp, Null))
   Else
     Log("Printing not supported.")
   End If
End Sub

Now I get an error in the line photoPrinter.InitializeNewInstance( :


Error occurred on line: 573 (Main)
java.lang.ClassNotFoundException: android.support$v4$print$PrintHelper
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:83)
at java.lang.reflect.Method.invoke(Native Method)
...


I am lost. What can I do to make that code work ?

I will appreciate any help.
 

MitchBu

Well-Known Member
Licensed User
Longtime User
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I just experimented with both the older canvas.b4a project that I was referring to in the OP, and the printing library.

Unfortunately, none of them print with sufficient resolution for what I need.

I need a minimum of 600 dpi. At present, I believe the printed resolution is 72 dpi, barely what an antique dot matrix printer from the eighties would do.

I have an app I got in the Play Store that prints at a much higher resolution, so I know it is possible to get much better results.

I found this in the Android Reference that apparently addresses directly my concern :
https://developer.android.com/reference/android/print/PrintAttributes.Resolution

Taking as example the program that prints using JavaObject, it seems to work somewhat like mediaSize.

Unfortunately, I am not familiar enough with JavaObject to create the code.

And I don't see how this could be applied to the Printer class.

Unless I find a way to print at minimum 600 dpi, this will stop any chance of completing my current project.

I will appreciate any assistance.
 
Upvote 0
Top