@@ -28,7 +28,7 @@ The compat library may be found on Maven Central repository. Add it to your proj
28
28
following dependency:
29
29
30
30
``` Groovy
31
- implementation 'no.nordicsemi.android.support.v18:scanner:1.4.4 '
31
+ implementation 'no.nordicsemi.android.support.v18:scanner:1.4.5 '
32
32
```
33
33
34
34
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
144
144
145
145
Starting from version 1.3.0, this library may emulate such feature on older Android versions.
146
146
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
148
148
background with given settings and will send the given ` PendingIntent ` when a device
149
149
matching filter is found. To lower battery consumption it is recommended to set
150
150
` ScanSettings.SCAN_MODE_LOW_POWER ` scanning mode and use filter, but even with those conditions fulfilled
151
151
** 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
153
153
[ the same] ( https://developer.android.com/reference/android/app/PendingIntent ) intent in parameter.
154
154
The service will be stopped when the last scan was stopped.
155
155
@@ -167,7 +167,7 @@ To use this feature:
167
167
Intent intent = new Intent (context, MyReceiver . class); // explicite intent
168
168
intent. setAction(" com.example.ACTION_FOUND" );
169
169
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 );
171
171
172
172
BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat . getScanner();
173
173
ScanSettings settings = new ScanSettings .Builder ()
@@ -176,7 +176,7 @@ To use this feature:
176
176
.build();
177
177
List<ScanFilter > filters = new ArrayList<> ();
178
178
filters. add(new ScanFilter .Builder (). setServiceUuid(mUuid). build());
179
- scanner. startScan(filters, settings, context, pendingIntent);
179
+ scanner. startScan(filters, settings, context, pendingIntent, requestCode );
180
180
```
181
181
182
182
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.
185
185
To stop scanning call:
186
186
187
187
``` 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.
189
189
Intent intent = new Intent (context, MyReceiver . class);
190
190
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 );
192
192
193
193
BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat . getScanner();
194
- scanner. stopScan(context, pendingIntent);
194
+ scanner. stopScan(context, pendingIntent, requestCode );
195
195
```
196
196
197
197
** Note:** Android versions 6 and 7 will not report any advertising packets when in Doze mode.
198
198
Read more about it here: https://developer.android.com/training/monitoring-device-state/doze-standby
199
199
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
+
200
204
## Background scanning guidelines
201
205
202
206
To save power it is recommended to use as low power settings as possible and and use filters.
0 commit comments