Android Question How to read device name ?

Pravee7094

Active Member
Hello all

Every mobile phone has a name (device name) and also we have to edit the device name if we want.
But the question is, How to read that the device name in B4a?

Any support?

Regards
Praveen
 

RJB

Active Member
Licensed User
Longtime User
B4X:
Dim r As Reflector
    Log("Hostname: " & r.RunStaticMethod("android.os.Build", "getString", Array("net.hostname"), Array As String("java.lang.String")))
From: https://www.b4x.com/android/forum/threads/net-hostname-with-reflector.53495/
I don't know what you are using it for but for information my router adds -Wireless or -Ethernet to the name so you might need something similar. I don't know if that is common to other routers.
 
Last edited:
Upvote 0

Pravee7094

Active Member
B4X:
Dim r As Reflector
    Log("Hostname: " & r.RunStaticMethod("android.os.Build", "getString", Array("net.hostname"), Array As String("java.lang.String")))
From: https://www.b4x.com/android/forum/threads/net-hostname-with-reflector.53495/
I don't know what you are using it for but for information my router adds -Wireless or -Ethernet to the name so you might need something similar. I don't know if that is common to other routers.
It works very well.
It shows the Model of the device and the Name of the device. But while showing the Device name, It shows only three letters even I set the long name as a Device name.

How I get the full Device name here? Any support?

Regards
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User

B4X:
Dim phone1 As Phone
Log(phone1.Model)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Log(phone1.Model)
this is not the user defineable devicename. It is the model. Samsung xxx for example.
My Device is Named ManfredNote10 and this is probably the Name the to is searching for.

Unfortunately i do not know a method to get this.

But searching google it looks like there should be a way.
 
Upvote 0

Pravee7094

Active Member
this is not the user defineable devicename. It is the model. Samsung xxx for example.
My Device is Named ManfredNote10 and this is probably the Name the to is searching for.

Unfortunately i do not know a method to get this.

But searching google it looks like there should be a way.
Yeah, I also exactly want the device name.
Is it possible to get the device name?
If yes what method should use to get the device name?
Any support?

Regards
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
this is not the user defineable devicename. It is the model. Samsung xxx for example.
My Device is Named ManfredNote10 and this is probably the Name the to is searching for.

Unfortunately i do not know a method to get this.

But searching google it looks like there should be a way.
Yes right, i read in a hurry. Maybe this is right
 
Upvote 0

Pravee7094

Active Member
Yes right, i read in a hurry. Maybe this is right
Hello sir,

I think you didnt understand my question yet.

There is a two type of name are there in the mobile phones. One is Model name and another one is device name.
Model name is standard we can't able to change. but device name is editable, we can change if we want.
And also got the code about How to read the model name of the mobile phones.

Question is :
How the read the Device name of the mobile phone?
If we change the Device name also got change in the output section.

Is there already tutorials for that? or code snippets?
Any support?

Thanks
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
How the read the Device name of the mobile phone?
B4X:
'Add Manifest
'AddPermission("android.permission.BLUETOOTH")
'AddPermission("android.permission.BLUETOOTH_ADMIN")
'AddPermission(android.permission.ACCESS_FINE_LOCATION)

    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result  Then
        Dim adapter As JavaObject
        adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethodJO("getDefaultAdapter", Null)
        Log("Name device: " & adapter.RunMethod("getName", Null))      
    End If
 
Last edited:
Upvote 0

Pravee7094

Active Member
B4X:
Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result  Then
        Dim adapter As JavaObject
        adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethodJO("getDefaultAdapter", Null)
        Log("Name device: " & adapter.RunMethod("getName", Null))      
    End If
very impressive. thanks a lot
 
Upvote 0

Pravee7094

Active Member
B4X:
'Add Manifest
'AddPermission("android.permission.BLUETOOTH")
'AddPermission("android.permission.BLUETOOTH_ADMIN")
'AddPermission(android.permission.ACCESS_FINE_LOCATION)

    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result  Then
        Dim adapter As JavaObject
        adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethodJO("getDefaultAdapter", Null)
        Log("Name device: " & adapter.RunMethod("getName", Null))     
    End If
Hi sir,
Using B4A 10.2
Works fine in Mobile with android version 9
Returns null in Tab with android version 4.1.2
Anything could be done to return correct value in android v 4.1.2 ?
 
Upvote 0
Top