0

I want to retrieve the Device Name field that the user can set in the System..About Phone section of the settings. How can I do this?

This is a field that the user can type any name into e.g. "Richard's Pixel".


This is not the same as the device model name as stored in android.os.Build.MODEL and related fields.

These are not duplicates of this question as they relate to the device model name:

This is not a duplicate as it relates to WIFI name:


This is not a duplicate as 1) some solutions return null, and 2) some solutions return the Bluetooth name configured in a different part of the settings (i.e. this is a different name):

The solutions that return null could just be out of date.

This link is updated and uses similar code, but it works on Android P. This is a duplicate of that post:

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • Ohhkk .. Need some digging i guess then.. – ADM Feb 05 '19 at 12:49
  • public String getLocalBluetoothName(){ if(mBluetoothAdapter == null){ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } String name = mBluetoothAdapter.getName(); I have tested this code in OnePlus 3T with Android 8.0 and it has worked. It returns the device name as set in the about phone. – Pronoy999 Feb 05 '19 at 13:04
  • 1
    What a coincidence . I was just about to post it as an answer xd. `Settings.Global.getString(getContentResolver(), "device_name")` .. Also i don't think all devices have this setting so it can return `null`. – ADM Feb 05 '19 at 13:04
  • But I have tested it. I changed the device name in About phone and it also reflects in the bluetooth device name. And vice-versa. I just now tested it in OnePlus 3T with Android 8.0. – Pronoy999 Feb 05 '19 at 13:06
  • @Pronoy Then it could be device specific - those are 2 very separate fields on the Pixel, which can be configured with very different values. – Richard Le Mesurier Feb 05 '19 at 13:11

0 Answers0