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

PhilipBrown

Active Member
Licensed User
Longtime User
The purpose of [the inline code] feature is to make it easier to access third party SDKs and also to allow developers to add existing Java code snippets to their projects.

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?
 

DonManfred

Expert
Licensed User
Longtime 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.
 
Upvote 0

PhilipBrown

Active Member
Licensed User
Longtime 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.

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?
 
Upvote 0

PhilipBrown

Active Member
Licensed User
Longtime 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?

B4X:
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:
Upvote 0
Top