ScanCallback


public abstract class ScanCallback
extends Object

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


Bluetooth LE scan callbacks. Scan results are reported using these callbacks.

Summary

Constants

int SCAN_FAILED_ALREADY_STARTED

Fails to start scan as BLE scan with the same settings is already started by the app.

int SCAN_FAILED_APPLICATION_REGISTRATION_FAILED

Fails to start scan as app cannot be registered.

int SCAN_FAILED_FEATURE_UNSUPPORTED

Fails to start power optimized scan as this feature is not supported.

int SCAN_FAILED_INTERNAL_ERROR

Fails to start scan due an internal error

int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES

Fails to start scan as it is out of hardware resources.

int SCAN_FAILED_SCANNING_TOO_FREQUENTLY

Fails to start scan as application tries to scan too frequently.

Public constructors

ScanCallback()

Public methods

void onBatchScanResults(List<ScanResult> results)

Callback when batch results are delivered.

void onScanFailed(int errorCode)

Callback when scan could not be started.

void onScanResult(int callbackType, ScanResult result)

Callback when a BLE advertisement has been found.

Inherited methods

Constants

SCAN_FAILED_ALREADY_STARTED

Added in API level 21
public static final int SCAN_FAILED_ALREADY_STARTED

Fails to start scan as BLE scan with the same settings is already started by the app.

Constant Value: 1 (0x00000001)

SCAN_FAILED_APPLICATION_REGISTRATION_FAILED

Added in API level 21
public static final int SCAN_FAILED_APPLICATION_REGISTRATION_FAILED

Fails to start scan as app cannot be registered.

Constant Value: 2 (0x00000002)

SCAN_FAILED_FEATURE_UNSUPPORTED

Added in API level 21
public static final int SCAN_FAILED_FEATURE_UNSUPPORTED

Fails to start power optimized scan as this feature is not supported.

Constant Value: 4 (0x00000004)

SCAN_FAILED_INTERNAL_ERROR

Added in API level 21
public static final int SCAN_FAILED_INTERNAL_ERROR

Fails to start scan due an internal error

Constant Value: 3 (0x00000003)

SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES

Added in API level 33
public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES

Fails to start scan as it is out of hardware resources.

Constant Value: 5 (0x00000005)

SCAN_FAILED_SCANNING_TOO_FREQUENTLY

Added in API level 33
public static final int SCAN_FAILED_SCANNING_TOO_FREQUENTLY

Fails to start scan as application tries to scan too frequently.

Constant Value: 6 (0x00000006)

Public constructors

ScanCallback

Added in API level 21
public ScanCallback ()

Public methods

onBatchScanResults

Added in API level 21
public void onBatchScanResults (List<ScanResult> results)

Callback when batch results are delivered.

Parameters
results List: List of scan results that are previously scanned.

onScanFailed

Added in API level 21
public void onScanFailed (int errorCode)

Callback when scan could not be started.

Parameters
errorCode int: Error code (one of SCAN_FAILED_*) for scan failure. Value is SCAN_FAILED_ALREADY_STARTED, SCAN_FAILED_APPLICATION_REGISTRATION_FAILED, SCAN_FAILED_INTERNAL_ERROR, SCAN_FAILED_FEATURE_UNSUPPORTED, SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES, or SCAN_FAILED_SCANNING_TOO_FREQUENTLY

onScanResult

Added in API level 21
public void onScanResult (int callbackType, 
                ScanResult result)

Callback when a BLE advertisement has been found.

Parameters
callbackType int: Determines how this callback was triggered. Could be one of ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanSettings.CALLBACK_TYPE_FIRST_MATCH or ScanSettings.CALLBACK_TYPE_MATCH_LOST

result ScanResult: A Bluetooth LE scan result.