Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bluetooth BLE discovery not seeing device

I'm trying to discover and connect to Bluetooth Low Energy (BLE) devices in my app. I have an implementation that is showing some devices and is able to bond and communicate with them just fine. However, one of my BLE devices (Saveo C200 LF) never shows up in my discovery scan.

I downloaded a BLE Scanner app from Google Play to see if the Saveo C200 would show up in their scan and it does. It shows up instantly and their app is able to connect to it and discover services and such.

I always see several devices show up in my discovery, and I'm able to connect to/bond with others, but I just can't get this one device to show up in my discovery at all, even though it shows up in the discovery for the BLE Scanner app.

But no matter what I do, I never find that device when I scan. I'm not using any filters. What am I missing in my attempts to scan?

private BLEScanCallback bleScanCallback = new BLEScanCallback();

public void bleStartBluetoothDiscovery() {
    BluetoothAdapter adapter = getBluetoothAdapter();
    if (adapter != null) {
        // for bluetooth le
        bleScanner = adapter.getBluetoothLeScanner();

        if (bleScanner != null) {           
            // run the discovery for 12 seconds and then automatically stop
            bleScheduleEndDiscovery(12);

            List<ScanFilter> filters = null;
            
            ScanSettings scanSettings = new ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .build()
            ;
            
            bleScanner.startScan(filters, scanSettings, this.bleScanCallback);

        }
    }
}


private static class BLEScanCallback extends ScanCallback {

    @Override
    public void onScanResult(int callbackType, ScanResult result) {
        BluetoothDevice device = result.getDevice();
        
        // the address of the Saveo C200 device, got it from the 
        // 3rd party BLE Scanner app that is able to see it when scanning.
        String crfidscanneraddress = "DD:0D:30:5E:1A:AC"; 
        
        String address = device.getAddress();
        String deviceName = device.getName();
        deviceName = (deviceName == null) ? "Unknown" : deviceName;

        if (address.equals(crfidscanneraddress)) {
            Log.d(TAG, "onScanResult: FOUND IT!!! ---> " + deviceName + " [" + address + "] ");
            // I'm not just relying on this log, I'm checking through
            // all of the results and my device is not found even
            // with a different address. 
        }

        Log.d(TAG, "onScanResult: " + deviceName + " [" + address + "] ");

    }

    // ... etc

}
like image 764
Kenny Wyland Avatar asked Oct 21 '25 23:10

Kenny Wyland


1 Answers

I was in the process of updating the question to include my permissions from my Manifest, and I noticed this one:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
    android:usesPermissionFlags="neverForLocation"
/>

I removed the android:usesPermissionFlags="neverForLocation" and the device instantly shows up in my discovery now.

I had put that in there because the docs suggested that I've I'm not actually trying to use the bluetooth scan to derive their physical location, then I could assert that I wasn't doing that. I figured that was a good idea for privacy purposes.

https://developer.android.com/develop/connectivity/bluetooth/bt-permissions

However, the docs also state that setting that flag will cause some results to be filtered out.

Strongly assert that your app doesn't derive physical location

If your app doesn't use Bluetooth scan results to derive physical location, you can make a strong assertion that your app never uses the Bluetooth permissions to derive physical location. To do so, complete the following steps:

Add the android:usesPermissionFlags attribute to your BLUETOOTH_SCAN permission declaration, and set this attribute's value to neverForLocation.

Note: If you include neverForLocation in your android:usesPermissionFlags, some BLE beacons are filtered from the scan results.

like image 134
Kenny Wyland Avatar answered Oct 23 '25 12:10

Kenny Wyland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!