陈奇
2018-11-01 cdbaf79d124d46b69dc62b653fde55f9d40b5534
FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java
@@ -102,6 +102,7 @@
            descriptor = characteristic.getDescriptor(descriptorUUID);
        }
        return this;
    }
@@ -117,7 +118,7 @@
     /*------------------------------- main operation ----------------------------------- */
    /*------------------------------- main operation ----------------------------------- */
    /**
@@ -341,21 +342,38 @@
                                                          final String uuid_notify) {
        if (bleCallback != null) {
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                bluetoothGatt.requestMtu(10);
//            }
            listenAndTimer(bleCallback, MSG_NOTIFY_CHA, uuid_notify, new BluetoothGattCallback() {
                AtomicBoolean msgRemoved = new AtomicBoolean(false);
                @Override
                public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
                    super.onConnectionStateChange(gatt, status, newState);
                }
                @Override
                public void onCharacteristicChanged(BluetoothGatt gatt,
                                                    BluetoothGattCharacteristic characteristic) {
                    if (!msgRemoved.getAndSet(true)) {
                        handler.removeMessages(MSG_NOTIFY_CHA, this);
                    }
                    if (characteristic.getUuid().equals(UUID.fromString(uuid_notify))) {
                        bleCallback.onSuccess(characteristic);
                    }
                }
                @Override
                public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
                    super.onMtuChanged(gatt, mtu, status);
                    System.out.println(String.format("onMtuChanged:mtu = %s", mtu));
                }
            });
        }
    }
@@ -372,7 +390,6 @@
                @Override
                public void onCharacteristicChanged(BluetoothGatt gatt,
                                                    BluetoothGattCharacteristic characteristic) {
                    if (!msgRemoved.getAndSet(true)) {
                        handler.removeMessages(MSG_INDICATE_DES, this);
                    }