diff --git a/app/release/app-release-3.5.0a.apk b/app/release/app-release-3.5.0a.apk index b68dbb8..0d39784 100644 Binary files a/app/release/app-release-3.5.0a.apk and b/app/release/app-release-3.5.0a.apk differ diff --git a/app/release/app-release.apk b/app/release/app-release.apk index b68dbb8..0d39784 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index 0d47be6..634f5bb 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -93,6 +93,7 @@ public class SdDataSourceBLE extends SdDataSource { public final static UUID UUID_HEART_RATE_MEASUREMENT = UUID.fromString(CHAR_HEART_RATE_MEASUREMENT); private BluetoothGatt mGatt; private BluetoothGattCharacteristic mBattChar; + private BluetoothGattCharacteristic mOsdChar; public SdDataSourceBLE(Context context, Handler handler, @@ -174,6 +175,9 @@ public class SdDataSourceBLE extends SdDataSource { Log.w(TAG, "BluetoothAdapter not initialized"); return; } + // Un-register for BLE Notifications. + setCharacteristicNotification(mOsdChar, false); + mBluetoothGatt.disconnect(); if (mBluetoothGatt == null) { return; @@ -253,6 +257,7 @@ public class SdDataSourceBLE extends SdDataSource { String charUuidStr = gattCharacteristic.getUuid().toString(); if (charUuidStr.equals(CHAR_OSD_ACC_DATA)) { Log.v(TAG, "Subscribing to Acceleration Data Change Notifications"); + mOsdChar = gattCharacteristic; setCharacteristicNotification(gattCharacteristic,true); } else if (charUuidStr.equals(CHAR_OSD_BATT_DATA)) { @@ -368,15 +373,28 @@ public class SdDataSourceBLE extends SdDataSource { Log.w(TAG, "BluetoothAdapter not initialized"); return; } - Log.v(TAG,"setCharacteristicNotification - Requesting notifications"); - mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); + if (enabled) { + Log.v(TAG, "setCharacteristicNotification - Requesting notifications"); + mBluetoothGatt.setCharacteristicNotification(characteristic, true); - // Tell the device we want notifications? The sample from Google said we only need this for Heart Rate, but the - // BangleJS widget did not work without it so do it for everything. + // Tell the device we want notifications? The sample from Google said we only need this for Heart Rate, but the + // BangleJS widget did not work without it so do it for everything. BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); + } else { + Log.v(TAG, "setCharacteristicNotification - De-registering notifications"); + mBluetoothGatt.setCharacteristicNotification(characteristic, false); + + // Tell the device we want notifications? The sample from Google said we only need this for Heart Rate, but the + // BangleJS widget did not work without it so do it for everything. + BluetoothGattDescriptor descriptor = characteristic.getDescriptor( + UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); + descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); + mBluetoothGatt.writeDescriptor(descriptor); + + } } /** diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index b93fb72..5c24fb6 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -161,8 +161,6 @@ public class SdServer extends Service implements SdDataReceiver { public SdServer() { super(); Log.i(TAG, "SdServer Created"); - mSdData = new SdData(); - mToneGenerator = new ToneGenerator(AudioManager.STREAM_ALARM, 100); } @Override @@ -186,6 +184,9 @@ public class SdServer extends Service implements SdDataReceiver { public void onCreate() { Log.i(TAG, "onCreate()"); mHandler = new Handler(); + mSdData = new SdData(); + mToneGenerator = new ToneGenerator(AudioManager.STREAM_ALARM, 100); + mUtil = new OsdUtil(getApplicationContext(), mHandler); mUtil.writeToSysLogFile("SdServer.onCreate()"); @@ -824,7 +825,7 @@ public class SdServer extends Service implements SdDataReceiver { } } else { Log.i(TAG, "sendSMSAlarm() - Phone Alarms Disabled - not doing anything!"); - mUtil.showToast(getString(R.string.phone_alarm_disabled)); + //mUtil.showToast(getString(R.string.phone_alarm_disabled)); } } diff --git a/app/src/main/res/menu/main_activity_actions.xml b/app/src/main/res/menu/main_activity_actions.xml index 9dd43a4..7afa63a 100644 --- a/app/src/main/res/menu/main_activity_actions.xml +++ b/app/src/main/res/menu/main_activity_actions.xml @@ -47,17 +47,18 @@ android:title="@string/test_sms_alarm_notification" />