Home » Android » java – onBatchScanResults is not called in Android BLE

java – onBatchScanResults is not called in Android BLE

Posted by: admin June 15, 2020 Leave a comment


I am now using the new BLE api in android developing.

Basic idea is using bluetooth scanning result to inflate the recyclerview(list);

I followed the BLE guide on google developer

Now I have two problem:
1. onBatchScanResults listener is never triggered, butonScanResult works well, is that because the scanner only sense 1 sensor nearby?

  1. my BLE scanner is much slower compared with other applications.

The following is the two core functions’ code snippet.

private void scanBLE(boolean enable) {
    final BluetoothLeScanner mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
    if (enable) {
        mScanning = true;
    } else {
        if (mScanning) {
            mScanning = false;

    Log.i(TAG, "now the scanning state is" + mScanning);

// Device scan callback.
private ScanCallback mScanCallback =
        new ScanCallback() {
    public void onScanResult(int callbackType, android.bluetooth.le.ScanResult result) {
        addBeaconTolist(result, beaconsList);

    public void onScanFailed(int errorCode) {
        Log.i(TAG, "error code is:" + errorCode);

    public void onBatchScanResults(java.util.List<android.bluetooth.le.ScanResult> results) {
        Log.i(TAG, "event linstener is called!!!!");
        Log.i(TAG, "batch result are:" + results);
        for (int i = 0; i < results.size(); i++) {
            ScanResult result = results.get(i);
            addBeaconTolist(result, beaconsList);


in MainFragment is like following:

    beaconsList = new ArrayList<BeaconsInfo>();

    mAdapter = new BeaconsAdapter(beaconsList);

How to&Answers:

Whether or not you get batch results or individual results depends on your scan settings.

  1. In order to get batch results, you need to adjust the ScanSettings. Check out the documentation for the ScanSettings.Builder, and try using SCAN_MODE_LOW_POWER, which batches up results. You can also try adjusting the batch interval with setReportDelay(long reportDelayMillis); You can see a blog post I wrote about the power benefits of these settings here.

  2. It’s not totally clear what you mean by “my BLE scanner is much slower compared with other applications”, but it may be that the app’s UI lags because you are not updating it on the UI thread. Try wrapping your calls to notifyDatasetChanged like this:

    runOnUiThread(new Runnable() {
      public void run() {


Try setUseHardwareBatchingIfSupported(true). This solves the problem for me on moto360 2nd gen. I think this is auto implemented for newer API.