Skip to content

Commit

Permalink
add onNotifySuccess() method in BleNotifyCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Ficat committed Oct 10, 2018
1 parent 63dcfa5 commit c949c0a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
5 changes: 5 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ notify和indicate都使用以下方法
@Override
public void onCharacteristicChanged(byte[] data, BleDevice device) {

}

@Override
public void onNotifySuccess(BleDevice device) {

}

@Override
Expand Down
24 changes: 24 additions & 0 deletions easyble/src/main/java/com/ficat/easyble/gatt/BleGattImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

public interface BleNotifyCallback extends BleCallback {
void onCharacteristicChanged(byte[] data, BleDevice device);

void onNotifySuccess(BleDevice device);
}
9 changes: 7 additions & 2 deletions sample/src/main/java/com/ficat/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -279,13 +279,18 @@ private void testNotify() {
BleDevice device = manager.getConnectedDevices().get(0);
//randomly finding a characteristic supporting notification to test
Map<String, String> notificationInfo = getSpecificServiceInfo(device, CHARACTERISTIC_NOTIFICATION);
for (Map.Entry<String, String> e : notificationInfo.entrySet()) {
for (final Map.Entry<String, String> 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();
Expand Down

0 comments on commit c949c0a

Please sign in to comment.