/** * ask to the node to notify when the feature change its value * @param feature feature to look * @return false if the feature is not handle by this node or disabled */ public boolean enableNotification(Feature feature){ if(!feature.isEnabled() || feature.getParentNode()!=this) return false; if(isEnableNotification(feature)) return true; BluetoothGattCharacteristic featureChar = getCorrespondingChar(feature); if(charCanBeNotify(featureChar)) { mNotifyFeature.add(feature); return changeNotificationStatus(featureChar, true); } return false; }//enableNotification
/** * unsubscribe the notification for the node update of the feature * @param feature feature that you want stop to be notify * @return false if the feature is not handle by this node or disabled */ public boolean disableNotification(Feature feature){ if(!feature.isEnabled() || feature.getParentNode()!=this) return false; BluetoothGattCharacteristic featureChar =getCorrespondingChar(feature); if(charCanBeNotify(featureChar)) { mNotifyFeature.remove(feature); //other things are send using that characateristic, so we don't have to //disable it if(characteristicsHasOtherEnabledFeatures(featureChar,feature)) return true; return changeNotificationStatus(featureChar,false); }// return false; }//disableNotification
/** * send a request for enable/disable the notification update on a specific characteristics * @param characteristic characteristics to notify * @param enable true if you want enable the notification, false if you want disable it * @return true if the request is correctly send, false otherwise */ boolean changeNotificationStatus(BluetoothGattCharacteristic characteristic, boolean enable){ if(charCanBeNotify(characteristic) && mConnection!=null && isConnected()){ BluetoothGattDescriptor descriptor = characteristic.getDescriptor(NOTIFY_CHAR_DESC_UUID); if(descriptor==null) return false; WriteDescCommand command = null; final int properties = characteristic.getProperties(); if((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) command = new WriteDescCommand(descriptor, enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); if((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) command = new WriteDescCommand(descriptor, enable ? BluetoothGattDescriptor.ENABLE_INDICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); if(command==null) return false; enqueueWriteDesc(command); return true; }else return false; }