diff --git a/README.md b/README.md index cc2e2a9..16cb84d 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,11 @@ Both notification and indication use the following method to set notfication or } + @Override + public void onNotifySuccess(BleDevice device) { + + } + @Override public void onFail(int failCode, String info, BleDevice device) { diff --git a/README_CN.md b/README_CN.md index d4c1020..2d4aaba 100644 --- a/README_CN.md +++ b/README_CN.md @@ -140,6 +140,11 @@ notify和indicate都使用以下方法 @Override public void onCharacteristicChanged(byte[] data, BleDevice device) { + } + + @Override + public void onNotifySuccess(BleDevice device) { + } @Override diff --git a/easyble/src/main/java/com/ficat/easyble/gatt/BleGattImpl.java b/easyble/src/main/java/com/ficat/easyble/gatt/BleGattImpl.java index e378c9a..e87b5b7 100644 --- a/easyble/src/main/java/com/ficat/easyble/gatt/BleGattImpl.java +++ b/easyble/src/main/java/com/ficat/easyble/gatt/BleGattImpl.java @@ -227,6 +227,30 @@ public void run() { }); } + @Override + public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { + super.onDescriptorWrite(gatt, descriptor, status); + if (status == BluetoothGatt.GATT_SUCCESS) { + String address = gatt.getDevice().getAddress(); + String serviceUuid = descriptor.getCharacteristic().getService().getUuid().toString(); + String characteristicUuid = descriptor.getCharacteristic().getUuid().toString(); + UuidIdentify identify = getUuidIdentifyFromMap(mNotifyCallbackMap, address, serviceUuid, characteristicUuid); + if (identify == null) { + return; + } + final BleNotifyCallback callback = mNotifyCallbackMap.get(identify); + final BleDevice device = getBleDeviceFromMap(address, mConnectCallbackMap); + mHandler.post(new Runnable() { + @Override + public void run() { + if (callback != null) { + callback.onNotifySuccess(device); + } + } + }); + } + } + @Override public void onReadRemoteRssi(BluetoothGatt gatt, final int rssi, int status) { super.onReadRemoteRssi(gatt, rssi, status); diff --git a/easyble/src/main/java/com/ficat/easyble/gatt/callback/BleNotifyCallback.java b/easyble/src/main/java/com/ficat/easyble/gatt/callback/BleNotifyCallback.java index 3e8d1bd..e85ae9f 100644 --- a/easyble/src/main/java/com/ficat/easyble/gatt/callback/BleNotifyCallback.java +++ b/easyble/src/main/java/com/ficat/easyble/gatt/callback/BleNotifyCallback.java @@ -5,4 +5,6 @@ public interface BleNotifyCallback extends BleCallback { void onCharacteristicChanged(byte[] data, BleDevice device); + + void onNotifySuccess(BleDevice device); } diff --git a/sample/src/main/java/com/ficat/sample/MainActivity.java b/sample/src/main/java/com/ficat/sample/MainActivity.java index c924181..84df43f 100644 --- a/sample/src/main/java/com/ficat/sample/MainActivity.java +++ b/sample/src/main/java/com/ficat/sample/MainActivity.java @@ -191,7 +191,7 @@ public void onLeScan(BleDevice device, int rssi, byte[] scanRecord) { @Override public void onStart(boolean startScanSuccess, String info) { Log.e(TAG, "start scan = " + startScanSuccess + " info: " + info); - if (startScanSuccess){ + if (startScanSuccess) { deviceList.clear(); adapter.notifyDataSetChanged(); } @@ -279,13 +279,18 @@ private void testNotify() { BleDevice device = manager.getConnectedDevices().get(0); //randomly finding a characteristic supporting notification to test Map notificationInfo = getSpecificServiceInfo(device, CHARACTERISTIC_NOTIFICATION); - for (Map.Entry e : notificationInfo.entrySet()) { + for (final Map.Entry e : notificationInfo.entrySet()) { manager.notify(device, e.getKey(), e.getValue(), new BleNotifyCallback() { @Override public void onCharacteristicChanged(byte[] data, BleDevice device) { Toast.makeText(MainActivity.this, "receive notification data" + new String(data), Toast.LENGTH_SHORT).show(); } + @Override + public void onNotifySuccess(BleDevice device) { + Log.e(TAG, "notify succcess: " + e.getValue()); + } + @Override public void onFail(int failCode, String info, BleDevice device) { Toast.makeText(MainActivity.this, "set notify fail: " + info, Toast.LENGTH_SHORT).show();