本文介绍了获取Android BluetoothDevice的重命名名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Android手机允许我通过转到[设置>无线&网络>蓝牙]活动页面,然后单击已配对的蓝牙设备右侧的设置按钮.但是,当我使用 BluetoothAdapter.getBondedDevices()函数,结果中显示的名称是设备的默认名称.
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?
推荐答案
您应使用别名.
用于设置重命名设备:
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();
}
获取设备名称:
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();
}
这篇关于获取Android BluetoothDevice的重命名名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!