method writeDescriptor in android ble always return false in lollipop -


when test code on 5.0.1 android version method writedescriptor return false. tested on 4.3 , 4.2.2 devices , it's returning true method:

public void setcharacteristicnotification(bluetoothgattcharacteristic characteristic,                                               boolean enabled) {         if (mbluetoothadapter == null || mbluetoothgatt == null) {             log.w(tag, "bluetoothadapter not initialized");             return;         }          mbluetoothgatt.setcharacteristicnotification(characteristic, enabled);          // specific heart rate measurement.         if (uuid_heart_rate_measurement.equals(characteristic.getuuid())) {             bluetoothgattdescriptor descriptor = characteristic.getdescriptor(                     uuid.fromstring(samplegattattributes.client_characteristic_config));             descriptor.setvalue(new byte[]{0x02});             boolean status = mbluetoothgatt.writedescriptor(descriptor);             if(status)                 log.d(tag,"client characteristic config changed 2");             else                 log.e(tag,"cannot set client characteristic config");         }     } 

the problem in method writedescriptor said

please see edited answer.

 public void setcharacteristicnotification(bluetoothgattcharacteristic  characteristic,                                           boolean enabled) {     if (mbluetoothadapter == null || mbluetoothgatt == null) {         log.w(tag, "bluetoothadapter not initialized");         return;     }      mbluetoothgatt.setcharacteristicnotification(characteristic, enabled);      // specific heart rate measurement.     if (uuid_heart_rate_measurement.equals(characteristic.getuuid())) {         bluetoothgattdescriptor descriptor = characteristic                 .getdescriptor(gattinfo.client_characteristic_config);         if(descriptor!=null)                 {           descriptor.setvalue(bluetoothgattdescriptor.enable_notification_value);         boolean status = mbluetoothgatt.writedescriptor(descriptor);         if(status)             log.d(tag,"client characteristic config changed 2");         else             log.e(tag,"cannot set client characteristic config");     }      } } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -