diff --git a/app/build.gradle b/app/build.gradle index d12aafc7..019bb9d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ dependencies { implementation 'no.nordicsemi.android.support.v18:scanner:1.1.0' // The DFU Library is imported automatically from jcenter: - implementation 'no.nordicsemi.android:dfu:1.6.1' + implementation 'no.nordicsemi.android:dfu:1.7.0' // if you desire to build the DFU Library, clone the // https://github.com/NordicSemiconductor/Android-DFU-Library project into DFULibrary folder, // add it as a module into the project structure and uncomment the following line @@ -57,7 +57,7 @@ dependencies { // Import the BLE Common Library. // The BLE Common Library depends on BLE Library. It is enough to include the first one. - implementation 'no.nordicsemi.android:ble-common:2.0-alpha5' + implementation 'no.nordicsemi.android:ble-common:2.0-beta5' // The BLE Common Library may be included from jcenter. If you want to modify the code, // clone both projects from GitHub and replace the line above with the following // (and also the according lines in the settings.gradle): diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java index 69588bad..15c89e2d 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java @@ -51,6 +51,7 @@ import no.nordicsemi.android.nrftoolbox.R; import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment; import no.nordicsemi.android.nrftoolbox.utility.DebugLogger; +@SuppressWarnings("unused") public abstract class BleProfileActivity extends AppCompatActivity implements BleManagerCallbacks, ScannerFragment.OnDeviceSelectedListener { private static final String TAG = "BaseProfileActivity"; @@ -228,6 +229,15 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl return null; } + /** + * This method returns whether autoConnect option should be used. + * + * @return true to use autoConnect feature, false (default) otherwise. + */ + protected boolean shouldAutoConnect() { + return false; + } + @Override public void onDeviceSelected(final BluetoothDevice device, final String name) { final int titleId = getLoggerProfileTitle(); @@ -240,7 +250,10 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl } mDeviceName = name; mBleManager.setLogger(mLogSession); - mBleManager.connect(device).enqueue(); + mBleManager.connect(device) + .useAutoConnect(shouldAutoConnect()) + .retry(3, 100) + .enqueue(); } @Override diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java index 3c44bfcc..af1a2826 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java @@ -228,6 +228,15 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct return null; } + /** + * This method returns whether autoConnect option should be used. + * + * @return true to use autoConnect feature, false (default) otherwise. + */ + protected boolean shouldAutoConnect() { + return false; + } + @Override public void onDeviceSelected(final BluetoothDevice device, final String name) { final int titleId = getLoggerProfileTitle(); @@ -240,7 +249,10 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct } mDeviceName = name; mBleManager.setLogger(mLogSession); - mBleManager.connect(device).enqueue(); + mBleManager.connect(device) + .useAutoConnect(shouldAutoConnect()) + .retry(3, 100) + .enqueue(); } @Override diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileService.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileService.java index 0958c370..27065537 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileService.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileService.java @@ -313,6 +313,15 @@ public abstract class BleProfileService extends Service implements BleManagerCal @SuppressWarnings("rawtypes") protected abstract BleManager initializeManager(); + /** + * This method returns whether autoConnect option should be used. + * + * @return true to use autoConnect feature, false (default) otherwise. + */ + protected boolean shouldAutoConnect() { + return false; + } + @Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) @@ -330,7 +339,10 @@ public abstract class BleProfileService extends Service implements BleManagerCal mBleManager.setLogger(mLogSession); onServiceStarted(); - mBleManager.connect(mBluetoothDevice).enqueue(); + mBleManager.connect(mBluetoothDevice) + .useAutoConnect(shouldAutoConnect()) + .retry(3, 100) + .enqueue(); return START_REDELIVER_INTENT; } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java index ae9b1ae3..6ce23b04 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java @@ -69,6 +69,7 @@ import no.nordicsemi.android.nrftoolbox.utility.DebugLogger; * listens for it. When entering back to the activity, activity will to bind to the service and refresh UI. *
*/ +@SuppressWarnings("unused") public abstract class BleProfileServiceReadyActivity