public void readManufacturer(){
BluetoothGattService manufacturerService = mBluetoothGatt.getService(UUID.fromString(MANUFACTURER_SERVICE));
if (manufacturerService != null) {
//Log.d("demo", String.valueOf(manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC))));
BluetoothGattCharacteristic manufacturerCharacteristic = manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC));
Log.d("demo", String.valueOf(manufacturerCharacteristic));
Log.d("demo", String.valueOf(manufacturerCharacteristic != null));
if (manufacturerCharacteristic != null) {
Log.d("demo","intoNotify");
setCharacteristicNotification(manufacturerCharacteristic,true);
}
}
}
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,boolean enable){
Log.d("demo", "setCharacteristicNotification");
if(mBluetoothAdapter == null || mBluetoothGatt == null){
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enable);
if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())){
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
}
打出来的Log:
08-11 14:58:54.594 4768-4768/com.example.chongyanghu.mybletest D/demo: readBatteryAction
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: android.bluetooth.BluetoothGattCharacteristic@1893971
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: true
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: intoNotify
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: setCharacteristicNotification
进入了setCharacteristicNotification,为什么没有回调onCharacteristicChanged方法,求大牛帮忙看看~