2

Here's my code for scanner callback.

private BluetoothAdapter.LeScanCallback mLeScanCallback =
    new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (device == null) {
                        return;
                    }
                    if (!device.getName().startsWith("DEVICE_NAME")) {
                        System.out.println("Did not start with DEVICE_NAME, removing: " + device.getName());
                        return;
                    }
                    if (!devices.contains(device)) {
                        System.out.println("Valid DEVICE_NAME Adding: " + device.getName());
                        devices.add(device);
                    }
                }
            });
        }
    };

I am getting a null BluetoothDevice object when I scan within certain geographic locations. For instance, it works perfectly fine within my home or place of work.

However, if I take my hardware + phone to the airport or big Marriott hotels then it messes up and returns me a null BluetoothDevice.

What does a null device mean, how can I go about fixing this?

Any advice would be appreciated.

Regards

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
Dylan Holmes
  • 335
  • 1
  • 6
  • 17

1 Answers1

1

I am getting a null BluetoothDevice object when I scan within certain geographic locations.

This should not happen if you've the same BLE devices around. In your place of work or home make sure the surrounding BLE devices are the same for testing purpose.

What does a null device mean

Simple as no devices found. But for reference I'm just quoting from developers guide.

You can only scan for Bluetooth LE devices or scan for Classic Bluetooth devices, as described in Bluetooth. You cannot scan for both Bluetooth LE and classic devices at the same time.

I would like to share some of my experience here. Some bluetooth devices need to be discoverable when you scan for nearby devices. You need to keep that in mind too.

Let me know if that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • 1
    I have custom hardware that has a pure BLE chip in it, it cannot do classic. It is the same device that I used at my home / work with no problems. And the scan callback is giving me a null device, meaning if I were to do operations on it I would receive Null Point Exception. If no device(s) are found shouldn't the scanLeCallback not even trigger, why give me a null device? In the developer's guide they don't even have a null check, they assume all devices found at that point are not null. – Dylan Holmes Aug 28 '16 at 12:35
  • 1
    Sounds interesting. Can you please have a look at this answer? http://stackoverflow.com/a/26361694/3145960 – Reaz Murshed Aug 28 '16 at 14:09
  • his problem looks a bit different because his BluetoothDevice isn't null, just the name of the device is null. But, I have yet to look at the AdvertisedData array, I'll look there to see what I can find. And report back, but assuming it's empty, what do you suggest? – Dylan Holmes Aug 28 '16 at 17:26