Ubiquitous
Ubiquitous

Reputation: 503

Getting the renamed name of an Android BluetoothDevice

My android phone allows me rename devices that I have paired with, by going to the [Settings > Wireless & Networkds > Bluetooth] Activity page and clicking the settings button to the right of a paired bluetooth device. However, when I query for a list of Bonded devices with the BluetoothAdapter.getBondedDevices() function, the name that shows up in the results is the default name for the device.

How can I access the renamed name for a Bluetooth device?

Upvotes: 9

Views: 4516

Answers (1)

Dmytro Batyuk
Dmytro Batyuk

Reputation: 974

You should use alias name.

For setting rename device:

try {
    Method method = device.getClass().getMethod("setAlias", String.class);
    if(method != null) {
        method.invoke(device, "new_device_name");
    }
} catch (NoSuchMethodException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
}

For getting device name:

String deviceAlias = device.getName();
try {
    Method method = device.getClass().getMethod("getAliasName");
    if(method != null) {
        deviceAlias = (String)method.invoke(device);
    }
} catch (NoSuchMethodException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
}

Upvotes: 17

Related Questions