Android NordicSemiconductor / Android-BLE-Library onCharacteristicChanged не вызывается - PullRequest
0 голосов
/ 20 мая 2019

Я использую эту библиотеку NordicSemiconductor / Android-BLE-Library для связи BLE и успешно могу подключить периферийное устройство.Я получаю услуги и характеристики и могу написать характеристики.

Но для чего-то после записи характеристик onCharacteristicChanged не вызывается.Хотя я сначала включаю уведомления, а потом пишу.

Вот так я включаю его с новой версией библиотеки.

setNotificationCallback(bluetoothGattCharacteristic).with(object : ProfileDataCallback {
        override fun onDataReceived(device: BluetoothDevice, data: Data) {
            BluetoothNotificationBus.getBus().post(BluetoothNotificationEvents.PostPeripheralValueForCharacteristicChangedNotification(device,bluetoothGattCharacteristic.service,bluetoothGattCharacteristic))
        }

        override fun onInvalidDataReceived(device: BluetoothDevice, data: Data) {
            BluetoothNotificationBus.getBus().post(BluetoothNotificationEvents.PostPeripheralValueForCharacteristicChangedNotification(device,bluetoothGattCharacteristic.service,bluetoothGattCharacteristic))
        }

    })
enableNotifications(bluetoothGattCharacteristic).enqueue()

Также в logcat:

2019-05-20 14:03:24.110 6148-6148/com.nextmunich.trumaandroidpoc D/BluetoothGatt: setCharacteristicNotification() - uuid: f47b0100-f3b2-11e8-8eb2-f2801f1b9fd1 enable: true

Также из BleManager.java , приведенный ниже метод возвращает true

@MainThread
private boolean internalEnableNotifications(final BluetoothGattCharacteristic characteristic) {
    final BluetoothGatt gatt = mBluetoothGatt;
    if (gatt == null || characteristic == null || !mConnected)
        return false;

    final BluetoothGattDescriptor descriptor = getCccd(characteristic, BluetoothGattCharacteristic.PROPERTY_NOTIFY);
    if (descriptor != null) {
        log(Log.DEBUG, "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
        gatt.setCharacteristicNotification(characteristic, true);

        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        log(Log.VERBOSE, "Enabling notifications for " + characteristic.getUuid());
        log(Log.DEBUG, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x01-00)");
        return internalWriteDescriptorWorkaround(descriptor);
    }
    return false;
}

Пожалуйста, ознакомьтесь с этой проблемой.Как я знаю, в stackoverflow есть разные потоки, но ни один из них не работал для меня.

Я также протестировал свой код с приложением nRF Connect , и кажется, что уведомление работает нормально.

...