Android Question How to use inline code to access 3rd party library

Discussion in 'Android Questions' started by PhilipBrown, Feb 26, 2015.

  1. PhilipBrown

    PhilipBrown Active Member Licensed User

    The way to write Java code snippets is well documented, but there do not seem to be any examples of how to use inline code to access third party SDKs. Does anyone have any examples?
     
    KZero likes this.
  2. DonManfred

    DonManfred Expert Licensed User

    i dont think that it is possible to write a GLOBAL tutorial about this.
    It depends on the 3rd party jr you want to wrap.
    There are simple ones and there are more complicated ones.
     
  3. PhilipBrown

    PhilipBrown Active Member Licensed User

    Hi Manfred,

    Even a very simple example would be very welcome!
    Maybe it would need to include a very simple library to give it context...
    Or maybe one of the standard libraries would do?
     
  4. DonManfred

    DonManfred Expert Licensed User

    i will have a look.
    Actually i´m working on a library-wrapper which, i think, can also be done using inline java to wrap the 3rd party jar. Means; it is not a complicated jar

    I will have a look at it and create an example if i figured it out
     
    KZero likes this.
  5. PhilipBrown

    PhilipBrown Active Member Licensed User

    Ok, so here's a simple example using the Phone library.

    You need to check Phone and JavaObject in the library tab to make it work.
    To discover the full name of the PhoneId method, look in the <b4a-installation-folder>\Libraries\Phone.xml
    In this case it's anywheresoftware.b4a.phone.Phone.PhoneId

    So now, I wonder if we can find a real-world example where the inline code provides something useful which you can't easily get by just using B4A?

    Code:
    Sub Process_Globals
        
    Private nativeMe As JavaObject
    End Sub

    Sub Globals
        
    Dim ID As PhoneId
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    If FirstTime Then
            nativeMe.InitializeContext
        
    End If

        
    Dim strPhoneNumber As String
        strPhoneNumber = nativeMe.RunMethod(
    "GetNumber"Array (ID))
        
    Log ("strPhoneNumber=" & strPhoneNumber)


    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub


    #If JAVA

    public String GetNumber(anywheresoftware.b4a.phone.Phone.PhoneId x) {
        return x.GetLine1Number();
    }

    #End If
     
    Last edited: Feb 26, 2015
  6. DonManfred

    DonManfred Expert Licensed User

    please use code tags when posting code!!!
     
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