Skip to content

Most visited

Recently visited

navigation

BluetoothLeScanner

public final class BluetoothLeScanner
extends Object

java.lang.Object
   ↳ android.bluetooth.le.BluetoothLeScanner


This class provides methods to perform scan related operations for Bluetooth LE devices. An application can scan for a particular type of Bluetooth LE devices using ScanFilter. It can also request different types of callbacks for delivering the result.

Use getBluetoothLeScanner() to get an instance of BluetoothLeScanner.

Note: Most of the scan methods here require BLUETOOTH_ADMIN permission.

See also:

Summary

Constants

String EXTRA_CALLBACK_TYPE

Optional extra indicating the callback type, which will be one of CALLBACK_TYPE_* constants in ScanSettings.

String EXTRA_ERROR_CODE

Optional extra indicating the error code, if any.

String EXTRA_LIST_SCAN_RESULT

Extra containing a list of ScanResults.

Public methods

void flushPendingScanResults(ScanCallback callback)

Flush pending batch scan results stored in Bluetooth controller.

int startScan(List<ScanFilter> filters, ScanSettings settings, PendingIntent callbackIntent)

Start Bluetooth LE scan using a PendingIntent.

void startScan(ScanCallback callback)

Start Bluetooth LE scan with default parameters and no filters.

void startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback)

Start Bluetooth LE scan.

void stopScan(ScanCallback callback)

Stops an ongoing Bluetooth LE scan.

void stopScan(PendingIntent callbackIntent)

Stops an ongoing Bluetooth LE scan started using a PendingIntent.

Inherited methods

From class java.lang.Object

Constants

EXTRA_CALLBACK_TYPE

String EXTRA_CALLBACK_TYPE

Optional extra indicating the callback type, which will be one of CALLBACK_TYPE_* constants in ScanSettings.

See also:

Constant Value: "android.bluetooth.le.extra.CALLBACK_TYPE"

EXTRA_ERROR_CODE

String EXTRA_ERROR_CODE

Optional extra indicating the error code, if any. The error code will be one of the SCAN_FAILED_* codes in ScanCallback.

Constant Value: "android.bluetooth.le.extra.ERROR_CODE"

EXTRA_LIST_SCAN_RESULT

String EXTRA_LIST_SCAN_RESULT

Extra containing a list of ScanResults. It can have one or more results if there was no error. In case of error, EXTRA_ERROR_CODE will contain the error code and this extra will not be available.

Constant Value: "android.bluetooth.le.extra.LIST_SCAN_RESULT"

Public methods

flushPendingScanResults

added in API level 21
void flushPendingScanResults (ScanCallback callback)

Flush pending batch scan results stored in Bluetooth controller. This will return Bluetooth LE scan results batched on bluetooth controller. Returns immediately, batch scan results data will be delivered through the callback.

Parameters
callback ScanCallback: Callback of the Bluetooth LE Scan, it has to be the same instance as the one used to start scan.

startScan

int startScan (List<ScanFilter> filters, 
                ScanSettings settings, 
                PendingIntent callbackIntent)

Start Bluetooth LE scan using a PendingIntent. The scan results will be delivered via the PendingIntent. Use this method of scanning if your process is not always running and it should be started when scan results are available.

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.

Requires the BLUETOOTH_ADMIN permission.

Parameters
filters List: Optional list of ScanFilters for finding exact BLE devices.

This value may be null.

settings ScanSettings: Optional settings for the scan.

This value may be null.

callbackIntent PendingIntent: The PendingIntent to deliver the result to.

This value must never be null.

Returns
int Returns 0 for success or an error code from ScanCallback if the scan request could not be sent.

See also:

startScan

added in API level 21
void startScan (ScanCallback callback)

Start Bluetooth LE scan with default parameters and no filters. The scan results will be delivered through callback.

An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get results.

Requires the BLUETOOTH_ADMIN permission.

Parameters
callback ScanCallback: Callback used to deliver scan results.

Throws
IllegalArgumentException If callback is null.

startScan

added in API level 21
void startScan (List<ScanFilter> filters, 
                ScanSettings settings, 
                ScanCallback callback)

Start Bluetooth LE scan. The scan results will be delivered through callback.

An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get results.

Requires the BLUETOOTH_ADMIN permission.

Parameters
filters List: ScanFilters for finding exact BLE devices.

settings ScanSettings: Settings for the scan.

callback ScanCallback: Callback used to deliver scan results.

Throws
IllegalArgumentException If settings or callback is null.

stopScan

added in API level 21
void stopScan (ScanCallback callback)

Stops an ongoing Bluetooth LE scan.

Requires the BLUETOOTH_ADMIN permission.

stopScan

void stopScan (PendingIntent callbackIntent)

Stops an ongoing Bluetooth LE scan started using a PendingIntent.

Requires the BLUETOOTH_ADMIN permission.

Parameters
callbackIntent PendingIntent: The PendingIntent that was used to start the scan.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.