Android Question javaobject, use class that require handler in it's constructor

fabton1963

Member
Licensed User
Longtime User
Hi ,
I try to use javaobjet to call an external library for usb printer, (dont suggest me "felusb" it doesn't work for me or better worked for three years and now crash),
the library I whould like to use ia named "printer.jar"
in pure JAVA I use the following code
java example:
import com.printer.posbank.Printer;

public class MainActivity extends Activity {
    …
    private Printer mPrinter;
    …
    public void onCreate(Bundle savedInstanceState) {
        …
        mPrinter = new Printer(this, mHandler, null);
        …
    }
    private final Handler mHandler = new Handler(new Handler.Callback() {
        public Boolean handleMessage(Message msg) {
            …
        }
    }
}

using b4a I try with adding printer.jar to externallib

b4a code:
#Region  Project Attributes
    ...   
    #AdditionalJar: printer
#End Region

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    Dim jo As JavaObject   
    Return jo.InitializeNewInstance("com.printer.posbank.Printer",Array As Object(GetContext,????,null))
    .....

End Sub

I don't know how I may pass the callback handler params because in the example I found the callback object use the javaobjet already initialized.

getpicasso tutorial:
   'third example: download image with callback
   Dim jo As JavaObject = GetPicasso
   Dim callback As Object = jo.CreateEvent("com.squareup.picasso.Callback", "Callback", Null)
   GetPicasso.RunMethodJO("load", Array(url)).RunMethodJO("into", Array(img1, callback))

Any suggestion?
 

fabton1963

Member
Licensed User
Longtime User
Now I create the printer object,
I may also call the RunMethodJO without crash but I still cannot handle the callback
sample:
Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    jPrinter = getPrinter
    'Dim callback As Object = jPrinter.CreateEvent("com.printer.posbank.Printer", "handleMessage", Null)
    'Dim callback As Object = jPrinter.CreateEvent("com.printer.posbank.Printer", "PrinterCallback", Null)
    jPrinter.RunMethodJO("findUsbPrinters",Null)
    
End Sub

Sub handler_Event (msg As Object) As Object
    Log (msg)
    Return Null
End Sub

Sub callback_Event (msg As Object) As Object
    Log (msg)
    Return Null
End Sub

Sub PrinterCallback_Event (msg As Object) As Object
    Log (msg)
    Return Null
End Sub

I attach the sample project and printer lib.
 

Attachments

  • A11.zip
    9.5 KB · Views: 113
  • Printer.zip
    144.3 KB · Views: 108
Upvote 0
Top