Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 980
Ubiquitous Avatar asked Dec 18 '13 12:12

Ubiquitous


1 Answers

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();
}
like image 140
Dmytro Batyuk Avatar answered Nov 03 '22 01:11

Dmytro Batyuk