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?
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With