【发布时间】:2013-11-19 05:48:29
【问题描述】:
我正在开发一个应用程序,我必须连接到 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 设备??
【问题讨论】:
-
您发现这些服务了吗?顺便说一句,变量的命名约定令人困惑。尽量不要在变量名的第一个字母中使用大写字母,因为这通常表示类而不是 java 中的变量。
-
@reTs:我修改了代码。我可以从 ble 设备中获取服务并读取名称,但是当我使用 writeCharacteristic 时它是错误的。
标签: android bluetooth bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean