我正在开发一个应用程序,我必须在 Android 4.3 上连接到蓝牙设备。
我想通过 Android 应用程序更改 CC2541 Keyfob 的名称。
我尝试使用 0x2A00 来获取设备名称服务,但是当我调用 Device_Name 函数时它似乎不起作用。
Name_Service 为空。
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));
我可以从 BLE 设备读取名称,但是当我使用 mBluetoothGatt.readCharacteristic(DeviceName) 时它显示 writeCharacteristic(DeviceName) 为 false。
有人尝试使用设备名称的 UUID(0x2A00) 将名称写入 BLE 设备吗??
最佳答案
需要修改CC2541 keyfob的固件,在keyfobdemo.c中的KeyFobApp_Init()中添加如下代码,添加设备名称的写入权限:
uint8 devNamePermission = GATT_PERMIT_READ|GATT_PERMIT_WRITE;
GGS_SetParameter( GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof ( uint8 ), &devNamePermission );
引用:http://processors.wiki.ti.com/index.php/CC2540_DeviceNameWrite
关于android - 如何在 Android 4.3 中更改蓝牙低功耗设备的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064136/