Android Question using external jar libraries with JavaObject

santiago

Member
Licensed User
Longtime User
I developed a software using an external bluetooth printer.It works fine. But I received a device with built-in printer. The vendor sent me the SDK and library and Eclipse example.
The library ,named j1009.jar has a folder with 2 files (.so files)

I copied the library and the folder inside VB4A libraries folder.

Extracted from the eclipse test program sended by provider I attach the library class structure

I tried to use the library in several ways using JavaObject but allways received an error message

I show the last attempt I wrote, but it is not the only one I tried

Here like the code in the JavaObject thread page
B4X:
#AdditionalJar:j1009

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

This is my last code :

B4X:
Sub printe AsJavaObject

Dim jo AsJavaObject

Return jo.InitializeStatic("com.bw.spdev.Printer")

End Sub



B4X:
Sub Button3_Click

Return printe.RunMethodJO("PrintString",Array("ggggg"))

End Sub


When click on button3, the error message is :
B4X:
An error in sub:java.lang
illegalArgumentException:
expected received of type com.bw.spdev.printer ,but got java.lang.Class<com.bw.spdev.Printer>


Vendor's documentation for Printer class incluye ….. Printer.PrintString(string)


Any help or technical orientation would be appreciated. If you need more information I will suply.

If not possible to use JavaObject I think I have two choices :
1.- Built a VB4A library from the j1009.jar library
2.- "capture" my vb4a project from Eclipse and add the library functions . But I think this is not possible.

Please , Could you send me links with related help for the easiest way you think is the best of both choices? ,well in case you think it is not possible to use JavaObject

Thanks in advance for your time and beg your pardon for my English or if the question is silly (I am not java developer).
 

santiago

Member
Licensed User
Longtime User
Here is the library structure extracted from Eclipse test program
 

Attachments

  • lib1.png
    lib1.png
    5.8 KB · Views: 162
Upvote 0

santiago

Member
Licensed User
Longtime User
Sorry , I am VB.net developer and B4A developer too, thats the mistake.

No , the files are in a folder next to the j1009.jar . I pasted all inside the B4A's library folder.

I attached the class printer Methods.
As you can see I want to use the method PrintString ( it has a green circle with not S-static )
I read a link sended by Roberto P with a similar problem (#Additionaljar and JavaObject how to do? ).
I sent him a personal message asking for help because he had a similar problem and fixed it with your help.

To learn I create a new project to test ONLY to print a text line .

Based on that thread I check to use the static method AddStringFun(string) and after the static PrintFun() . Both with but with not success and error messages.

Any additional information you can request I can send.

Again, thanks.
 

Attachments

  • lib2.png
    lib2.png
    32.8 KB · Views: 148
Upvote 0

santiago

Member
Licensed User
Longtime User
Sorry , when I said I checked the AddStringFun and PrintFun I wrote this code

B4X:
  Return Printe.RunMethod("AddStringFun",Array("wwwww"))
Return printe.RunMethodJO("PrintFun",Null)

Both with RunMethod and RunMethodJO .
 
Upvote 0

santiago

Member
Licensed User
Longtime User
Of course !!!
I will send you the library and the example but its size exceeded the 512k . Please could you provide an e-mail address to send it ?

I tried and fail.First because I used the rar extension and at least for its size.Sorry!!!
 

Attachments

  • PED API Programming GuideV1.1.3.pdf
    455.4 KB · Views: 554
Upvote 0

santiago

Member
Licensed User
Longtime User
Thanks,

Is it an standard Java wrapper or specially designed for B4A?

If it is special for B4A , please , could you send me links to documents to investigate? If it is standard procedure, could you send me links to "easy explained" procedures description web pages?. I would appreciate the information sources.

On the other hand , I must tell you the example is big because it shows how to use another device's functions ,or capabilities , like card-reader ,scanner,smart card,etc. But I am not able to take-off that code areas.

I would like to know if it is possible to translate the B4A project to Eclipse (I think not) or to B4J , add the library and work from Java environment?

On any case, I appreciated the B4A team help .Thanks so much
 
Upvote 0

santiago

Member
Licensed User
Longtime User
I have another idea . Can ( or must) I ask the provider to send me a wrapper or something that help?
I do not know what to ask . Maybe the wrapper would be difficoult to me but easy for them.

What do you think?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
See the tutorials here: https://www.b4x.com/android/forum/forums/libraries-developers-questions.32/

It requires some Java knowledge.

I would like to know if it is possible to translate the B4A project to Eclipse (I think not) or to B4J , add the library and work from Java environment?
Theoretically it is possible to take the generated Java code and modify it with Eclipse. It is not really practical (it will be simpler to create a library and use it from B4A).
 
Upvote 0
Top