| | |
| | | descriptor = characteristic.getDescriptor(descriptorUUID); |
| | | } |
| | | |
| | | |
| | | return this; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /*------------------------------- main operation ----------------------------------- */ |
| | | /*------------------------------- main operation ----------------------------------- */ |
| | | |
| | | |
| | | /** |
| | |
| | | if (getCharacteristic() != null |
| | | && (getCharacteristic().getProperties() | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { |
| | | BleLog.w(TAG, "characteristic.getProperties():" + getCharacteristic().getProperties()); |
| | | |
| | | System.out.println("chenqi enableCharacteristicNotify =>" + uuid_notify); |
| | | |
| | | handleCharacteristicNotificationCallback(bleCallback, uuid_notify); |
| | | |
| | |
| | | |
| | | listenAndTimer(bleCallback, MSG_NOTIFY_CHA, uuid_notify, new BluetoothGattCallback() { |
| | | AtomicBoolean msgRemoved = new AtomicBoolean(false); |
| | | |
| | | @Override |
| | | public void onCharacteristicChanged(BluetoothGatt gatt, |
| | | BluetoothGattCharacteristic characteristic) { |
| | | |
| | | if (!msgRemoved.getAndSet(true)) { |
| | | handler.removeMessages(MSG_NOTIFY_CHA, this); |
| | | } |
| | | |
| | | System.out.println("chenqi Notify Hex ->" + BleBluetooth.dumpHex(characteristic.getValue())); |
| | | |
| | | if (characteristic.getUuid().equals(UUID.fromString(uuid_notify))) { |
| | | bleCallback.onSuccess(characteristic); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void onCharacteristicChanged(BluetoothGatt gatt, |
| | | BluetoothGattCharacteristic characteristic) { |
| | | |
| | | System.out.println("chenqi Notify Hex indicate->" + BleBluetooth.dumpHex(characteristic.getValue())); |
| | | if (!msgRemoved.getAndSet(true)) { |
| | | handler.removeMessages(MSG_INDICATE_DES, this); |
| | | } |
| | |
| | | public void onCharacteristicWrite(BluetoothGatt gatt, |
| | | BluetoothGattCharacteristic characteristic, int status) { |
| | | handler.removeMessages(MSG_WRITE_CHA, this); |
| | | System.out.println("chenqi Notify Hex write->" + BleBluetooth.dumpHex(characteristic.getValue())); |
| | | |
| | | |
| | | if (status == BluetoothGatt.GATT_SUCCESS) { |
| | | if (characteristic.getUuid().equals(UUID.fromString(uuid_write))) { |
| | |
| | | @Override |
| | | public void onCharacteristicRead(BluetoothGatt gatt, |
| | | BluetoothGattCharacteristic characteristic, int status) { |
| | | System.out.println("chenqi Notify Hex indicate read->" + BleBluetooth.dumpHex(characteristic.getValue())); |
| | | |
| | | if (!msgRemoved.getAndSet(true)) { |
| | | handler.removeMessages(MSG_READ_CHA, this); |
| | | } |
| | |
| | | @Override |
| | | public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { |
| | | handler.removeMessages(MSG_READ_RSSI, this); |
| | | System.out.println("chenqi Notify Hex rssi->" + BleBluetooth.dumpHex(characteristic.getValue())); |
| | | |
| | | if (status == BluetoothGatt.GATT_SUCCESS) { |
| | | bleCallback.onSuccess(rssi); |
| | | } else { |
| | |
| | | private void listenAndTimer(BleCallback bleCallback, int what, String uuid, BluetoothGattCallback callback) { |
| | | bleCallback.setBluetoothGattCallback(callback); |
| | | bleBluetooth.addGattCallback(uuid, callback); |
| | | |
| | | Message msg = handler.obtainMessage(what, bleCallback); |
| | | handler.sendMessageDelayed(msg, timeOutMillis); |
| | | } |