public abstract class BluetoothLeScannerCompat extends Object
ScanFilter. It
can also request different types of callbacks for delivering the result.
Use getScanner() to get an instance of the scanner.
Since version 1.3.0 of the Scanner Compar Library library,
PendingIntentReceiver and ScannerService will be added to AndroidManifest
whether the scanning with PendingIntent feature is used or not.
The ScannerService is used to emulate such scanning on platforms
before Oreo, while PendingIntentReceiver is used to translate from native
ScanResult to compat ScanResult and apply additional
filtering.
Note: Most of the scan methods here require
Manifest.permission#BLUETOOTH_ADMIN permission.
ScanFilter| Modifier and Type | Field and Description |
|---|---|
static String |
EXTRA_CALLBACK_TYPE
Optional extra indicating the callback type, which will be one of
CALLBACK_TYPE_* constants in
ScanSettings. |
static String |
EXTRA_ERROR_CODE
Optional extra indicating the error code, if any.
|
static String |
EXTRA_LIST_SCAN_RESULT
Extra containing a list of ScanResults.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
flushPendingScanResults(ScanCallback callback)
Flush pending batch scan results stored in Bluetooth controller.
|
static BluetoothLeScannerCompat |
getScanner()
Returns the scanner compat object
|
void |
startScan(List<ScanFilter> filters,
ScanSettings settings,
android.content.Context context,
android.app.PendingIntent callbackIntent)
Start Bluetooth LE scan using a
PendingIntent. |
void |
startScan(List<ScanFilter> filters,
ScanSettings settings,
ScanCallback callback)
Start Bluetooth LE scan.
|
void |
startScan(List<ScanFilter> filters,
ScanSettings settings,
ScanCallback callback,
android.os.Handler handler)
Start Bluetooth LE scan.
|
void |
startScan(ScanCallback callback)
Start Bluetooth LE scan with default parameters and no filters.
|
void |
stopScan(android.content.Context context,
android.app.PendingIntent callbackIntent)
Stops an ongoing Bluetooth LE scan.
|
void |
stopScan(ScanCallback callback)
Stops an ongoing Bluetooth LE scan.
|
public static final String EXTRA_LIST_SCAN_RESULT
EXTRA_ERROR_CODE will contain the error code and this
extra will not be available.public static final String EXTRA_ERROR_CODE
ScanCallback.public static final String EXTRA_CALLBACK_TYPE
ScanSettings.ScanCallback.onScanResult(int, android.bluetooth.le.ScanResult),
Constant Field Valuespublic static BluetoothLeScannerCompat getScanner()
public final void startScan(ScanCallback callback)
callback.
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
An app must hold
ACCESS_FINE_LOCATION permission
in order to get results.
callback - Callback used to deliver scan results.IllegalArgumentException - If callback is null.public final void startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback)
callback.
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
An app must hold
ACCESS_FINE_LOCATION permission
in order to get results.
filters - ScanFilters for finding exact BLE devices.settings - Optional settings for the scan.callback - Callback used to deliver scan results.IllegalArgumentException - If settings or callback is null.public final void startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback, android.os.Handler handler)
callback.
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
An app must hold
ACCESS_FINE_LOCATION permission
in order to get results.
filters - ScanFilters for finding exact BLE devices.settings - Optional settings for the scan.callback - Callback used to deliver scan results.handler - Optional handler used to deliver results.IllegalArgumentException - If settings or callback is null.public final void stopScan(ScanCallback callback)
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
callback - The callback used to start scanning.public final void startScan(List<ScanFilter> filters, ScanSettings settings, android.content.Context context, android.app.PendingIntent callbackIntent)
PendingIntent. The scan results will be delivered
via the PendingIntent. On platforms before Oreo this will start ScannerService
which will scan in background using given settings.
This method of scanning is intended to work in background. Long running scanning may
consume a lot of battery, so it is recommended to use low power mode in settings,
offloaded filtering and batching. However, the library may emulate batching, filtering or
callback types ScanSettings.CALLBACK_TYPE_FIRST_MATCH and
ScanSettings.CALLBACK_TYPE_MATCH_LOST if they are not supported.
A PendingIntentReceiver and ScannerService will be added to AndroidManifest
whether this feature is used or not.
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
An app must hold
ACCESS_FINE_LOCATION permission
in order to get results.
When the PendingIntent is delivered, the Intent passed to the receiver or activity will
contain one or more of the extras EXTRA_CALLBACK_TYPE, EXTRA_ERROR_CODE and
EXTRA_LIST_SCAN_RESULT to indicate the result of the scan.
filters - ScanFilters for finding exact BLE devices.settings - Optional settings for the scan.context - Context used to start ScannerService.callbackIntent - The PendingIntent to deliver the result to.IllegalArgumentException - If settings or callback is null.public final void stopScan(android.content.Context context,
android.app.PendingIntent callbackIntent)
Requires Manifest.permission#BLUETOOTH_ADMIN permission.
context - Context used to stop ScannerService.callbackIntent - The PendingIntent that was used to start the scan.public abstract void flushPendingScanResults(ScanCallback callback)
callback.callback - Callback of the Bluetooth LE Scan, it has to be the same instance as the one
used to start scan.