Я разрабатываю приложение на Samsung ACE3 для подключения устройства Bluetooth Low Energy. Поскольку Samsung не хочет, чтобы ACE3 обновлялся до Android 4.3, мне нужно использовать Samsung ble api. В настоящее время подключение, чтение данных, отправка данных и получение уведомления по одной характеристике - все в порядке. Но когда я включаю уведомление для нескольких характеристик, только первые включенные характеристики могут получать уведомление. У кого-нибудь есть такая же проблема? Ценю вашу помощь!
Следующий код включает уведомление при подключении
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);
}
Ниже приведен метод enableNotification:
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);
}