更改Android的蓝牙设备名称蓝牙、名称、设备、Android

2023-09-05 10:57:29 作者:爱而不得

我知道这是可能获得本地设备名称在溶液中描述了这个问题显示Android的蓝牙设备名称

I know it's possible to get the local device name as described in the solution to this question Display Android Bluetooth Device Name

什么,我很想知道的是,我可以改变当地buetooth名(一个其它设备看到,当我在发现模式)programaticlly。我知道你可以手动修改它,但我正在写和应用程序,我希望能够用相同的应用程序更改名称(添加一个简单的标志),所以其他设备可以扫描并立即知道如果手机还运行该应用程序。

What I'm interested in knowing is, can I change the local buetooth name (the one other devices see when I'm in discovery mode) programaticlly. I know you can change it by hand, but I'm writing and app and I want to be able to change the name (add a simple flag) so other devices with the same application can scan and instantly know if the phone is also running the app.

TL;博士:我如何更改蓝牙设备名称,在Android

tl;dr: How can I change the bluetooth device name on android?

推荐答案

是的,你可以改变使用设备名称的setName(字符串名称) BluetoothAdapter type.Following的是样品code:

Yes you can change your device name using setName(String name) of BluetoothAdapter type.Following is the sample code:

    private BluetoothAdapter bluetoothAdapter = null;
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    void ChangeDeviceName(){
                    Log.i(LOG, "localdevicename : "+bluetoothAdapter.getName()+" localdeviceAddress : "+bluetoothAdapter.getAddress());
                    bluetoothAdapter.setName("NewDeviceName");
                    Log.i(LOG, "localdevicename : "+bluetoothAdapter.getName()+" localdeviceAddress : "+bluetoothAdapter.getAddress());
                }