How can I get the device name in Android?

Viewed 52790

How can I get the device name programmatically in Android?

9 Answers

You can get the device name from android.provider.Settings using :

Settings.Global.getString(context.getContentResolver(), "device_name")

The name and model of your Android Device can be found like this:

String manufacturerModel = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL;

Using following way can get the device name and also in case user modify the device name, it can also get the updated name:

Settings.Secure.getString(getContentResolver(), “bluetooth_name”); 

Because bluetooth_name is not a documented API, in case it returns null, you can use following code instead: (note that this API is only available since Android 7.1 and per my testing, it CANNOT get the device name immediately after user modified)

Settings.System.getString(getContentResolver(), “device_name”);

Here is how to get the name that the user set in the "About Phone" "Device name" screen using adb:

$ adb shell 'settings get global device_name'
Related