Skip to content

Commit

Permalink
Version 0.0.5 update - added GATT server side monitoring on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
plugnburn committed Oct 26, 2017
1 parent 97927dc commit 0e647eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "xyz.a831337.colorbuzz"
minSdkVersion 22
targetSdkVersion 25
versionCode 4
versionName '0.0.4'
versionCode 5
versionName '0.0.5'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionNameSuffix '-alpha'
}
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/xyz/a831337/colorbuzz/BuzzService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BuzzService extends NotificationListenerService {
private BluetoothDevice btDevice;
private BluetoothGattCharacteristic operationChar;
private BluetoothGattCharacteristic monitoringChar;
private BluetoothGattDescriptor monitoringCharDescriptor;
private BluetoothGatt gattInstance;
private String charString;
private String readCharString;
Expand Down Expand Up @@ -107,10 +108,10 @@ public void run() {
}
if(charObj.getUuid().compareTo(readCharUuid) == 0) {
UUID notifyUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattDescriptor charDescriptor = charObj.getDescriptor(notifyUuid);
charDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
monitoringCharDescriptor = charObj.getDescriptor(notifyUuid);
monitoringCharDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
charObj.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
gatt.writeDescriptor(charDescriptor);
gatt.writeDescriptor(monitoringCharDescriptor);
gatt.setCharacteristicNotification(charObj, true);
BuzzService.this.setMonitoringChar(charObj);
}
Expand Down Expand Up @@ -239,8 +240,12 @@ public class ScreenActionReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if(BuzzService.this.activated) {
if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
monitoringCharDescriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
gattInstance.writeDescriptor(monitoringCharDescriptor);
gattInstance.setCharacteristicNotification(monitoringChar, false);
} else if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
monitoringCharDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gattInstance.writeDescriptor(monitoringCharDescriptor);
gattInstance.setCharacteristicNotification(monitoringChar, true);
}
}
Expand Down

0 comments on commit 0e647eb

Please sign in to comment.