1

I am trying to get multiple returns from BLE devices on Android.

I only get a single response.

This used to work on older devices.

My devices is running 5.0.2.

Here is my code:

    @TargetApi(Build.VERSION_CODES.M)
private void api21Scan(UUID[] uuids) {

    List<ScanFilter> scanFilters = new ArrayList<ScanFilter>();

    if (uuids != null) {
        for (int i = 0; i < uuids.length; ++i)
            scanFilters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(uuids[i].toString())).build());
    }

    ScanSettings settings = new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).build();
    ScanCallback scanCallback = new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result)
        {
            mLeScanCallback.onLeScan(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results)
        {
            for (ScanResult sr : results)
            {
                mLeScanCallback.onLeScan(sr.getDevice(), sr.getRssi(), sr.getScanRecord().getBytes());
            }
        }
    };

    if (uuids != null)
        mBluetoothAdapter.getBluetoothLeScanner().startScan(scanFilters, settings, scanCallback);
    else
        mBluetoothAdapter.getBluetoothLeScanner().startScan(null, settings, scanCallback);
}

In LogCat while my app is scanning I do see constant output of lines from TAG: bt-btm where the text says: new address: XX:XX:XX:XX:XX:XX where I see my device over and over.

Why are these scans not getting to my app?

I also have legacy code that uses the deprecated bluetooth adapter startLeScan and it also returns only the first scan of a device.

user856232
  • 1,073
  • 2
  • 14
  • 40
  • Maybe you could check out this http://stackoverflow.com/questions/29731176/ble-scanning-callback-only-get-called-several-times-then-stopped. – aleksamarkoni Jun 30 '16 at 14:35
  • So the root problem is that again we see fragmentation from Android device makers. Great...Thank you for pointing me to that post. I guess in the end it is up to us devs to work around manufacturer differences. – user856232 Jun 30 '16 at 18:23

0 Answers0