androidbluetooth-lowenergybeaconaltbeacon

Bluetooth scan methods - PendingIntent or ScanCallback?


my application scans BLE devices in background. I don't understand what determines the choice between these two methods: advantage / disadvantage. (I tested both and it works)

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

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

thank you for help


Solution

  • Android 8+ allows you to deliver Bluetooth scan results with two different messaging transports: Callback and Intent.

    Callback

    This makes a call to a method you define with the scan results.

    Pros:

    Cons:

    Intent

    This delivers the scan results to a BroadcastReceiver using Android’s Intent messaging structure

    Pros:

    Cons: