Notify on characteristic only trigger one time



  • We implemented the changes of V3 to listen on the characteristic, but the event triggers only one time. This is our method:

    private void enableNotifyLockState() {
            Log.d(LOG_TAG, "enableNotifyLockState: ");
            StartApplication.getDevice().enableNotify(new BleNotify(SERVICE, LOCKSTATE).setNotificationListener(new NotificationListener() {
                @Override
                public void onEvent(NotificationEvent notificationEvent) {
                    if (notificationEvent.wasSuccess()) {
                    Log.d(LOG_TAG, "NOTIFY LOCK STATE value: " + notificationEvent.data_byte());
                     //SOME CODE
    
                    } else {
                        Log.e(LOG_TAG, "NOTIFY ERROR LOCK_STATE " + notificationEvent.status());
                    }
                }
            }));
        }
    

    We also try ReadWriteListener instead of the NotificationListener, like in version 2 but the event only triggers one time.



  • FYI, when enabling/disabling notifications/indications, the first callback you get is to let you know if the enabling/disabling worked.

    After looking over the code, you're correct, the way you're using it, it will only fire the event saying if it worked or not. We'll adjust the behavior of this for the next release to set this listener as the default if there isn't one already set.

    For now, I'd recommend setting the notification listener on the device (rather than via the enableNotify method). BleDevice.setListener_Notification is the method to use for this.



  • I've updated the logic for enabling/disabling notifications. Now if you pass in a notification listener in a BleNotify instance, it will set that listener as the default only if there are no other NotificationListeners set for the device. This will be in the next version.