Get continuous RSSI values BLE

Viewed 477

I want to do BLE scanning in Android and here is my code -

try {
        if (Build.VERSION.SDK_INT < 21) {
            Log.d(TAG, "Starting BLE scan (SDK < 21)");
            bluetoothAdapter.startLeScan(this);
        }
        else {
            try {
                Log.d(TAG, "Starting BLE scan (SDK >= 21)");
                androidBleScanner.startScan(filters, settings, androidScannerCallback);
            } catch (NullPointerException e) {
                Log.w(TAG, "BLE scan for SDK >= 21 failed, using fallback to SDK < 21!");
                e.printStackTrace();
                bluetoothAdapter.startLeScan(this);
            }
        }

    } catch (NullPointerException e) {
        Log.e(TAG, "Fatal error trying to start BLE scanner!");
    }

The problem is it only does scanning once and gives me RSSI value once which I receive it in -

 @Override
    public void onLeScan(BluetoothDevice bluetoothDevice, int rssi, byte[] bytes) {
        //RSSI got only once
    }

How can I scan for 30 seconds and keep getting continuous RSSI values?

0 Answers
Related