Q:

How to get remote devices custom Bluetooth name in Android?

I'd like to retrieve a custom name of remote Bluetooth device in Android.
I'm talking about the name that is found in phones' settings under Settings/Bluetooth and paired device.
E.g. I have a remote Bluetooth device that has name "DoorControl". Under Settings->Bluetooth->paired devices, I have renamed the device as "CTRL". Now I'd like to access the defined name so I can display it for the user.
I'd like to display that name in list of Bluetooth devices.
knownDevicesAdapter.clear();
knownDevicesArray = mBluetoothAdapter.getBondedDevices();

if (knownDevicesArray.size() > 0) {
    for (BluetoothDevice device : knownDevicesArray) {
        if (device.getName().contains("Door")) {
            knownDevicesAdapter.add(device.getName() 
                    + /*HERE I WANT THE CUSTOM NAME TO SHOW*/ "\n" 
                    + device.getAddress());
        }
    }
}

device.getName(), returns only the full original name of the device, what is in this case "DoorControl".
This would be necessary since there can be 4 devices with the name DoorControl. Only way to tell the difference between them is by their address. But for the user friendly approach it would be much easier to let them rename the device in Bluetooth settings and just show that name as "nickname" for the device.
Is there way to access the custom name, so I don't have to write the full "rename->save the name for certain address->load the name"-cycle in my own application?
EDIT:
After searching for a while, I decided to write renaming ability in my own application, since I couldn't find out a way to get the names otherwise.
If anyone is reading this and knows the answer to my original question, I'd be happy to know it.

A:

In your app, you can rename a Bluetooth device like this:
public boolean renamePairedDevice(BluetoothDevice bluetoothDevice, String name) {
    try {
        Method m = bluetoothDevice.getClass().getMethod("setAlias", String.class);
        m.invoke(bluetoothDevice, name);
        return true;
    } catch (Exception e) {
        Log.d(TAG, "error renaming device:" + e.getMessage());
        return false;
    }
}

Then afterwards, bluetoothDevice.getName() will return the new name.
This has the same effect like renaming your Bluetooth devices in your device's settings.

A:

The problem I found was the getName() function only returns the default device name, not the alias name that the user can set.  In my case, I have multiple of the same devices paired and their default name is "Motorola T605".  I can't tell them apart so I use Android settings to rename them. Still, getName() returned "Motorola T605".  I needed to get the Alias name. The function for that exists but is not exposed. You can see it in this Java class: https://android.googlesource.com/platform/frameworks/base/+/56a2301/core/java/android/bluetooth/BluetoothDevice.java This worked for me.
First get the array of paired devices:
Set<BluetoothDevice> pairedDevices = mBTA.getBondedDevices();

Then loop through the array:
for (BluetoothDevice device : pairedDevices) 

Then see if you can find an alias name:
                           String name = null;

                        try {
                            Method m = device.getClass().getMethod("getAlias");
                            Object res = m.invoke(device);
                            if(res != null)
                            name = res.toString();
                        } catch (NoSuchMethodException e) {
                            e.printStackTrace();
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }

                        if(name == null)
                        name = device.getName();

If you can't get an alias, get the normal name.  I could do a better job of preventing and handling exceptions but it seems to work.

