6

I have implemented the following BLE scan callback,

private final ScanCallback mScanCallback = new ScanCallback() {
    @Override
    public void onScanResult(int callbackType, ScanResult result) {
        Log.d(TAG,"onScanResult: " +result.toString());
        runOnUiThread(() -> {
            if (result.getDevice().getName() != null && getString(R.string.unknown_device_text).compareTo(result.getDevice().getName().toLowerCase()) != 0) {
                mLeDeviceListAdapter.addDevice(result.getDevice());
                mLeDeviceListAdapter.notifyDataSetChanged();
            }
        });
        super.onScanResult(callbackType, result);
    }

    @Override
    public void onBatchScanResults(List<ScanResult> results) {
        Log.d(TAG,"onBatchScanResults: " +results.toString());
        super.onBatchScanResults(results);
    }

    @Override
    public void onScanFailed(int errorCode) {
        Log.d(TAG,"onScanFailed: errorCode: " +errorCode);
        super.onScanFailed(errorCode);
    }
};

However, in this callback I am not getting BLE devices that are advertising extended message. In contrast, in same place nRF app shows extended devices in their list.

Here is my scan method,

private void scanLeDevice() {

    List<ScanFilter> filters = new ArrayList<>();
    ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder();
    filters.add(scanFilterBuilder.build());

    ScanSettings.Builder settingsBuilder = new ScanSettings.Builder();
    settingsBuilder.setPhy(ScanSettings.PHY_LE_ALL_SUPPORTED);

    final BluetoothLeScanner bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
    
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            bluetoothLeScanner.stopScan(mScanCallback);
            Log.d(TAG, "scanLeDevice stopScan called");
        }
    }, SCAN_PERIOD);            

    bluetoothLeScanner.startScan(filters, settingsBuilder.build(), mScanCallback);
}

So, how can I filter and find the devices with extended advertising capabilities.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • I assume you are running both apps on the same hardware. Which [ScanSettings](https://developer.android.com/reference/android/bluetooth/le/ScanSettings) do you use? Have you set [PHY_LE_ALL_SUPPORTED](https://developer.android.com/reference/android/bluetooth/le/ScanSettings#PHY_LE_ALL_SUPPORTED) – Risto Dec 15 '22 at 11:17
  • @Risto Yes both apps in same device, Galaxy Flip4. I also added my scan method. No luck even with scan settings. – Sazzad Hissain Khan Dec 15 '22 at 11:26

1 Answers1

3

In order to show extended advertisements, you need to use the setLegacy(false) method. By default this is set to true, which is why you need to change it when setting up your scan settings.

Have a look at the links below for more information:-

UPDATE

You can filter only BLE devices that are doing extended adverts by checking the advert type. You can access the advert type by reading the scanRecord (e.g. using the getBytes method). You can read further on how to read the advert type here and here. Legacy adverts will be one of the following 4 types:-

  1. ADV_IND
  2. ADV_DIRECT_IND
  3. ADV_NONCONN_IND
  4. ADV_SCAN_IND

While extended adverts will be one of the following 4 types:

  1. ADV_EXT_IND
  2. AUX_ADV_IND
  3. AUX_SYNC_IND
  4. AUX_CHAIN_IND

This can be see in more details in the table below:-

enter image description here

Below are some other useful links on understanding the meaning of advert packets:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72