Android Question using external jar libraries with JavaObject

Discussion in 'Android Questions' started by santiago, May 31, 2015.

  1. santiago

    santiago Member Licensed 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
    Code:
    #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 :

    Code:
    Sub printe AsJavaObject

    Dim jo AsJavaObject

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

    End Sub


    Code:
    Sub Button3_Click

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

    End Sub

    When click on button3, the error message is :
    Code:
    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).
     
  2. santiago

    santiago Member Licensed User

    Here is the library structure extracted from Eclipse test program
     

    Attached Files:

  3. Erel

    Erel Administrator Staff Member Licensed User

    Note that the product name is B4A not VB4A.

    Are the so files located inside the jar file?
     
  4. santiago

    santiago Member Licensed 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.
     

    Attached Files:

  5. santiago

    santiago Member Licensed User

    Sorry , when I said I checked the AddStringFun and PrintFun I wrote this code

    Code:
    Return Printe.RunMethod("AddStringFun",Array("wwwww"))
    Return printe.RunMethodJO("PrintFun",Null)
    Both with RunMethod and RunMethodJO .
     
  6. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

    If possible , can you post a Java Example for using this .jar ? probably sent by the developer
     
  7. santiago

    santiago Member Licensed 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!!!
     

    Attached Files:

  8. Erel

    Erel Administrator Staff Member Licensed User

    You will need to create a Java wrapper library for this that will include the so files.
     
  9. santiago

    santiago Member Licensed 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
     
  10. santiago

    santiago Member Licensed 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?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    See the tutorials here: http://www.b4x.com/android/forum/forums/libraries-developers-questions.32/

    It requires some Java knowledge.

    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).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice