获取 Android BluetoothDevice 的重命名名称 [英] Getting the renamed name of an Android BluetoothDevice

查看:56
本文介绍了获取 Android BluetoothDevice 的重命名名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 android 手机允许我重命名配对的设备,方法是转到 [设置 > 无线 &Networkds > Bluetooth] 活动页面,然后单击配对蓝牙设备右侧的设置按钮.但是,当我使用 查询绑定设备列表时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 的重命名名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆