通知和断开问题

时间:2016-07-26 08:38:26

标签: rxandroidble

我们正在尝试使用您的框架升级现有应用程序,其他工作正常,如连接/读/写,但我们正面临通知/断开连接的问题

请您指导下列情况: -

  1. 需要回拨断开连接
  2. 通知无效我们无法收到任何通知提醒
  3. 是否有任何方法可以检查设备的特性,因为我们有不同的设备,并且所有设备都没有某些特性,当我们尝试在设备上读取/写入非现有的chacraterstics时,它会引发异常和应用程序崩溃
  4. 代码: -

    connection.writeDescriptor(
        Defs.SVC_AUTOMATIONIO_UUID, 
        Defs.CHAR_AUTOMATION_IO,
        Defs.DESC_CLIENT_CHAR_CONFIGURATION_UUID,
        BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
    )
        .subscribe(
            this::onWriteSuccess,
            this::onWriteFailure
        );
    
    connection.setupNotification(iCharUuid)
        .flatMap(notificationObservable -> notificationObservable)
        .subscribe(
            this::onNotificationReceived,
            this::onConnectionFailure
        );
    

    由于 Swayam

1 个答案:

答案 0 :(得分:0)

通常,您不必手动编写描述符来启用通知。图书馆为你做。

尝试:(example)

rxBleConnection.setupNotification(Defs.DESC_CLIENT_CHAR_CONFIGURATION_UUID)
                    .flatMap(notificationObservable -> notificationObservable)
                    .subscribe(this::onNotificationReceived, this::onNotificationSetupFailure);

为了获得断开连接的回调:(example)

  1. 您可以通过establishConnection方法观察onError。
  2. 您可以设置连接状态observable
  3. bleDevice.observeConnectionStateChanges().subscribe(this::onConnectionStateChange);

    要检查您可以使用服务发现的特征:(example)

     bleDevice.establishConnection(this, false)
                    .flatMap(RxBleConnection::discoverServices)
                    .first() // Disconnect automatically after discovery
                    .subscribe(this::processDiscoveredServices, this::onConnectionFailure);