简体   繁体   中英

How to change the name of bluetooth low energy device in Android 4.3?

I am developing an application where I have to connect to Bluetooth device on Android 4.3.

And I want to change the name of CC2541 Keyfob via the Android application.

I have trying to use 0x2A00 to get the Device Name service , but it seen not working when I call the Device_Name function.

The Name_Service is null.

 private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");



    public void Device_Name(){
        BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
        if(Name_Service == null) {
            Log.d(TAG, "Name_Service service not found!");
            return;
        }

        BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
        if(DeviceName == null) {
            Log.d(TAG, "DeviceName charateristic not found!");
            return;
        }

    }


Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));

String i = "123";       
DeviceName.setValue(i);
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));

I can read the name from BLE device , but it show writeCharacteristic(DeviceName) is false when I use mBluetoothGatt.readCharacteristic(DeviceName).

Does somebody has trying to use the UUID(0x2A00) of Device Name to write the name to BLE device ??

You need to modify the firmware of CC2541 keyfob to add the write permission of device name by adding the code below into KeyFobApp_Init() inside keyfobdemo.c:

uint8 devNamePermission = GATT_PERMIT_READ|GATT_PERMIT_WRITE; 
GGS_SetParameter( GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof ( uint8 ), &devNamePermission );

Reference: http://processors.wiki.ti.com/index.php/CC2540_DeviceNameWrite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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