Android Question Print to Internal Printer

Erel

Administrator
Staff member
Licensed User
I haven't checked the SDK. If it is simple enough then you can access it with #AdditionalJar and JavaObject.
 

Martin Fernandez

Member
Licensed User
I work the example
When I run this error appears:

java.lang.IllegalArgumentException: expected receiver of type android.device.PrinterManager, but got java.lang.Class<android.device.PrinterManager>

This is my code:

B4X:
#AdditionalJar: platform_sdk_v2.4.0810

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Callback_Event (MethodName As String, Args() As Object) As Object
    If MethodName = "onSuccess" Then
        ToastMessageShow("Success!!!", True)
    Else If MethodName = "onError" Then
        ToastMessageShow("Error!", True)
    End If
    Return Null
End Sub

Sub GetPrinter As JavaObject
    Dim jo As JavaObject
    'com.squareup.picasso.Picasso.with(context)
    Return jo.InitializeStatic("android.device.PrinterManager")
End Sub

Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub


Sub Button1_Click
    GetPrinter.RunMethodJO("open",Null)
    Log(GetPrinter.RunMethodJO("open",Null))
End Sub
 

Erel

Administrator
Staff member
Licensed User
This error means that 'open' is not a static method. You need to call it with an instance. You should probably use jo.InitializeNewInstance to create the instance. The exact call depends on the Java API.
 
Top