Question

I am trying to develop an app capable of detecting Bluetooth Low Energy Signals and thanks to an Adapter, show it in a Listview. At the moment has worked perfectly but now what I want to do is the onLeScan method so that when the scan has found a device, it compares the device and the rssi value with all the elements of the list. If both parameters are the same as the one of the items of the list, it doesn't call the adapter to add the device found. However, when I compile the code, it detects the BLE signals but the rssi value doesn´t changes.

Here is the code I used:

// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
    new BluetoothAdapter.LeScanCallback() {

        @Override
        public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    int size = leDeviceListAdapter.getCount();
                    for(int j = 0 ; j < size ; j++) {
                        BluetoothDevice devices = leDeviceListAdapter.getDevice(j);
                        Integer signal = leDeviceListAdapter.getRSSI(j);
                        if (devices!=device && signal!=rssi){
                            return;
                        }
                    }
                    leDeviceListAdapter.addDevice(device, rssi);
                    leDeviceListAdapter.notifyDataSetChanged();



                }
            });

        }

Does anyone know how to solve this problem? Please Help!!!! If it is necessarily I will put the whole code.

Was it helpful?

Solution

The rssi value is the signal strength. It's not the unique identifier for the BluetoothDevice. You should use the Bluetooth Address for that. device.getAddress();

OTHER TIPS

On some devices calling startLeScan once is enough to keep getting updates. On other devices you need to stop the scan and restart it again to get the updates.

I noticed this difference when testing with Nexus 7 and nexus 5. Do not know which needed the restart.

So my default implementation now starts, waits 2 seconds and stops again and so on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top