Android 三星ble api无法从多个GATT特征获取通知
我正在三星ACE3上开发一个应用程序,用于连接蓝牙低能设备。因为三星不希望ACE3升级到Android 4.3,所以我需要使用三星ble api。目前,连接、读取数据、发送数据以及从一个特性获取通知都是可以的。但是,当我为多个特征启用通知时,只有第一个启用的特征才能获得通知。有人有同样的问题吗?谢谢你的帮助 下面的代码是在连接时启用通知Android 三星ble api无法从多个GATT特征获取通知,android,bluetooth-lowenergy,samsung-mobile,gatt,Android,Bluetooth Lowenergy,Samsung Mobile,Gatt,我正在三星ACE3上开发一个应用程序,用于连接蓝牙低能设备。因为三星不希望ACE3升级到Android 4.3,所以我需要使用三星ble api。目前,连接、读取数据、发送数据以及从一个特性获取通知都是可以的。但是,当我为多个特征启用通知时,只有第一个启用的特征才能获得通知。有人有同样的问题吗?谢谢你的帮助 下面的代码是在连接时启用通知 if (mBluetoothGatt != null && device != null) { BluetoothGattSe
if (mBluetoothGatt != null && device != null) {
BluetoothGattService pucService = mBluetoothGatt.getService(device, PROFILE_UART_CONTROL_SERVICE);
if (pucService == null) {
showMessage("PUC service not found!");
return;
}
BluetoothGattCharacteristic motion = pucService.getCharacteristic(MOTION_READ);
if (motion == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, motion);
BluetoothGattCharacteristic voltage = pucService.getCharacteristic(VOLTAGE_READ);
if (voltage == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, voltage);
BluetoothGattCharacteristic pressure = pucService.getCharacteristic(PRESSURE_READ);
if (pressure == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, pressure);
}
以下是启用通知方法:
public boolean enableNotification(boolean enable, BluetoothGattCharacteristic characteristic) {
if (mBluetoothGatt == null)
return false;
if (!mBluetoothGatt.setCharacteristicNotification(characteristic, enable))
return false;
BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC);
if (clientConfig == null)
return false;
if (enable) {
Log.i(TAG,"enable notification");
clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
} else {
Log.i(TAG,"disable notification");
clientConfig.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
}
return mBluetoothGatt.writeDescriptor(clientConfig);
}
我刚刚意识到这个问题是由miznick在年的第二次回答中提出的。这主要是因为Samsung BLE Api的行为是同步的。基本上,api一次只能处理1条Gatt指令,如写/读特征、w/r描述符等。通过调用w/r GATT方法,它就像将GATT指令附加到等待执行的系统中一样。执行后,系统将调用相关的回调方法,如onCharacterWrite、OnDescriptorWrite等。只有在这一点上或之后,我们才应该称之为另一种Gatt w/r方法。代码在miznick的帖子中给出 也有助于理解三星Ble api的行为。一定要看看三星BLE官方网站上的指南和提示