Android Question BlueTooth How to get the connected device name

GMan

Well-Known Member
Licensed User
Longtime User
Depending on the connected device my App should show a different start screen.
How can i get the name of that device in B4A to play with ?
 

mfstuart

Active Member
Licensed User
Longtime User
Hi GMan,
I've created a Code Module that gets all the attributes of a tablet. I then store those attributes in a SQLite table for later use when the app connects to a LAN network.

Libraries used:
Core
JavaObject
Phone
Reflection
SQL

B4X:
Sub Process_Globals
    Dim ph As Phone
   
    Dim dvcDeviceID As String
    Dim dvcManufacturer As String
    Dim dvcModel As String
    Dim dvcProduct As String
    Dim dvcSdkVersion As String
    Dim dvcOSVersion As String
    Dim dvcAndroidID As String
    Dim dvcSQLiteVersion As String
    Dim dvcIPAddress As String
End Sub

sub functions:
B4X:
Sub DeviceInfo_Fetch
    dvcDeviceID = GetDeviceID
    dvcManufacturer = ph.Manufacturer
    dvcModel = ph.Model
    dvcProduct = ph.Product
    dvcSdkVersion = ph.SdkVersion
    dvcOSVersion = GetOSVersion
    dvcAndroidID = ph.GetSettings("android_id")
    dvcSQLiteVersion = GetSQLVersion
    dvcIPAddress = GetIPAddress   
End Sub

Sub GetDeviceID As String
    Dim id As String
    Dim rf As Reflector
    Dim Api As Int
   
    Api = rf.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    If Api < 9 Then
        'old device
        id = ph.GetSettings("android_id")
    Else
        'new device
        id = rf.GetStaticField("android.os.Build", "SERIAL")
        If id.ToLowerCase = "unknown" Then id = ph.GetSettings("android_id")
    End If
    Return id
End Sub

Sub GetOSVersion As String
    Dim OS As String
   
    Select dvcSdkVersion
        Case 2 : OS = "1.1"
        Case 3 : OS = "1.5"
        Case 4 : OS = "1.6"
        Case 5 : OS = "2.0"
        Case 6 : OS = "2.0.1"
        Case 7 : OS = "2.1"
        Case 8 : OS = "2.2"
        Case 9 : OS = "2.3"
        Case 10 : OS = "2.3.x"    '2.3.3 or 2.3.7
        Case 11 : OS = "3.0"
        Case 12 : OS = "3.1"
        Case 13 : OS = "3.2.x"
        Case 14 : OS = "4.0.x"
        Case 15 : OS = "4.0.3"
        Case 16 : OS = "4.1.x"
        Case 17 : OS = "4.2.x"
        Case 18 : OS = "4.3.x"
        Case 19 : OS = "4.4.x"
        Case 21 : OS = "5.0"
        Case 22 : OS = "5.1"
        Case 23 : OS = "6.0"
        Case 24 : OS = "7.0"
        Case 25 : OS = "7.1"
        Case Else : OS = ">7.1"
    End Select
    Return OS
End Sub

Sub GetSQLVersion As String
    Dim cur As Cursor
    Dim V As String = ""
   
    cur = Main.SQLcn.ExecQuery("SELECT sqlite_version() as sqlite_version")
    If cur.RowCount > 0 Then
        cur.Position = 0
        V = cur.GetString2(0)
    End If
    cur.Close
    Return V
End Sub

Sub GetIPAddress As String
    Dim ip As String = ""
    Dim jo As JavaObject
    jo.InitializeContext
    ip = jo.RunMethod("getIp", Array("wlan0"))
    Return ip
End Sub

HTH,
Mark S.
 
Upvote 0
Top