Android Question How to obtain/get/gather the phone device name

ShawnYang

Member
Hi Everybody.
I wanna to get the device name of the phone, but Phone library only have Model property to get the Model of the Phone that is not i want to get.
Even i look around all the properties of the Phone library might be, i didn't find it.
Could you please give me some trick or advice or some useful libraries.
Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The only name that you can get is the "Bluetooth name":

B4X:
Private Sub Button1_Click
    Wait For (GetBluetoothName) Complete (Result As String)
    If Result <> "no permission" Then
        Log("Name: " & Result)
    Else
        Log("no permission!")
    End If
End Sub

Private Sub GetBluetoothName As ResumableSub
    Dim rp As RuntimePermissions
    Dim phone As Phone
    If phone.SdkVersion >= 31 Then
        rp.CheckAndRequest("android.permission.BLUETOOTH_CONNECT")
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        If Result = False Then
            Return "no permission"
        End If
    End If
    Dim adapter As JavaObject
    adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter", Null)
    Dim name As JavaObject = adapter.RunMethod("getName", Null)
    Return IIf(name.IsInitialized, name, "")
End Sub

And add to manifest editor:
B4X:
AddPermission(android.permission.BLUETOOTH_CONNECT)
AddPermission(android.permission.BLUETOOTH)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…