Skip to content

Commit e861cdd

Browse files
committed
Version 1.4.5
1 parent 3cd68f0 commit e861cdd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The compat library may be found on Maven Central repository. Add it to your proj
2828
following dependency:
2929

3030
```Groovy
31-
implementation 'no.nordicsemi.android.support.v18:scanner:1.4.4'
31+
implementation 'no.nordicsemi.android.support.v18:scanner:1.4.5'
3232
```
3333

3434
Projects not migrated to Android Jetpack should use version 1.3.1, which is feature-equal to 1.4.0.
@@ -144,12 +144,12 @@ your application has been killed (the receiver must be added in *AndroidManifest
144144

145145
Starting from version 1.3.0, this library may emulate such feature on older Android versions.
146146
In order to do that, a background service will be started after calling
147-
`scanner.startScan(filters, settings, context, pendingIntent)`, which will be scanning in
147+
`scanner.startScan(filters, settings, context, pendingIntent, requestCode)`, which will be scanning in
148148
background with given settings and will send the given `PendingIntent` when a device
149149
matching filter is found. To lower battery consumption it is recommended to set
150150
`ScanSettings.SCAN_MODE_LOW_POWER` scanning mode and use filter, but even with those conditions fulfilled
151151
**the battery consumption will be significantly higher than on Oreo+**. To stop scanning call
152-
`scanner.stopScan(context, pendingIntent)` with
152+
`scanner.stopScan(context, pendingIntent, requestCode)` with
153153
[the same](https://developer.android.com/reference/android/app/PendingIntent) intent in parameter.
154154
The service will be stopped when the last scan was stopped.
155155

@@ -167,7 +167,7 @@ To use this feature:
167167
Intent intent = new Intent(context, MyReceiver.class); // explicite intent
168168
intent.setAction("com.example.ACTION_FOUND");
169169
intent.putExtra("some.extra", value); // optional
170-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
170+
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
171171

172172
BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
173173
ScanSettings settings = new ScanSettings.Builder()
@@ -176,7 +176,7 @@ To use this feature:
176176
.build();
177177
List<ScanFilter> filters = new ArrayList<>();
178178
filters.add(new ScanFilter.Builder().setServiceUuid(mUuid).build());
179-
scanner.startScan(filters, settings, context, pendingIntent);
179+
scanner.startScan(filters, settings, context, pendingIntent, requestCode);
180180
```
181181

182182
Add your `MyRecever` to *AndroidManifest*, as the application context might have been released
@@ -185,18 +185,22 @@ and all broadcast receivers registered to it together with it.
185185
To stop scanning call:
186186

187187
```java
188-
// To stop scanning use the same or an equal PendingIntent (check PendingIntent documentation)
188+
// To stop scanning use the same PendingIntent and request code as one used to start scanning.
189189
Intent intent = new Intent(context, MyReceiver.class);
190190
intent.setAction("com.example.ACTION_FOUND");
191-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
191+
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
192192

193193
BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
194-
scanner.stopScan(context, pendingIntent);
194+
scanner.stopScan(context, pendingIntent, requestCode);
195195
```
196196

197197
**Note:** Android versions 6 and 7 will not report any advertising packets when in Doze mode.
198198
Read more about it here: https://developer.android.com/training/monitoring-device-state/doze-standby
199199

200+
**Note 2:** An additional parameter called `requestCode` was added in version 1.4.5 to the above API.
201+
It is to ensure that the scanning would be correctly stopped. If not provided, a request code equal
202+
to 0 will be used preventing from having multiple scanning tasks.
203+
200204
## Background scanning guidelines
201205

202206
To save power it is recommended to use as low power settings as possible and and use filters.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# org.gradle.parallel=true
1919
android.useAndroidX=true
2020

21-
VERSION_NAME=1.4.4
21+
VERSION_NAME=1.4.5
2222
GROUP=no.nordicsemi.android.support.v18
2323

2424
POM_DESCRIPTION=Android Bluetooth LE Scanner Compat library

0 commit comments

Comments
 (0)