简体   繁体   English

如何通过程序重命名Android蓝牙配对设备?

[英]How to rename Android bluetooth paired device by programmly?

I need to "rename" bluetooth paired device of Android phone with programming. 我需要使用编程“重命名” Android手机的蓝牙配对设备。 But searching results are most discuss about local bluetooth rename method. 但是搜索结果是有关本地蓝牙重命名方法的最多讨论。 And it could use setname() to complete. 它可以使用setname()完成。 Does there have any method to rename "paired device" of Android phone ? 有什么方法可以重命名Android手机的“配对设备”吗?

I know the question is old, but I just needed this and found out how to do it. 我知道这个问题很旧,但是我只是需要这个,并找到了解决方法。 It uses reflexion so I'm not sure this is the best way to go but it works. 它使用反射,所以我不确定这是最好的方法,但是它可以工作。

public void renamePairDevice(BluetoothDevice device, String name) 
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
{
    Method m = device.getClass().getMethod("setAlias", String.class);
    m.invoke(device, name);
}

I don't think you can rename the name of the paired device. 我认为您无法重命名配对设备的名称。 You can only change the name from the paired device's settings. 您只能从配对设备的设置中更改名称。

Think of it like a wifi router, you cannot change the name of the router, but you can only connect to it. 将其视为wifi路由器,您无法更改路由器的名称,但只能连接到它。

However if you want,you could assign this way 但是,如果您愿意,可以指定这种方式

Set<BluetoothDevice> devices = btAdapter.getBondedDevices();
    if (devices.size() > 0) {
         for(int i=0;i<device.size();i++) {
            mDevice[i] = device;
            bondedDevices.add(mDevice.getName());


        }
    }

That way you could get the name of the paired Devices as a mDevice array. 这样,您可以将配对的设备的名称作为mDevice数组获得。 Hope it solved your issue 希望它能解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM