如何在android BLE中表达chainging BLE rssi?

时间:2017-02-10 07:19:26

标签: bluetooth-lowenergy rssi

我正在尝试在显示已扫描设备的列表中显示chainging rssi。

[在此处输入图像说明] [1]

我想在图片中表达rssi:_____的rsing值。 我能够在日志上获得chasiing rssi值,就像图片一样。

[在此输入图像说明] [2]

请帮帮我。

1 个答案:

答案 0 :(得分:0)

您需要扫描intervall,"刷新" RSSI通过重新扫描设备。 STH。像这样:

public void scanLeDevice(final boolean enable)
{
    final static int SCAN_PERIOD = 2000; //2s
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    final BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();

    //to start or stop scanning (true/false)
    if (enable)
    {
        // Stops scanning after a pre-defined scan period
        mHandler.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                mBluetoothAdapter.stopLeScan(mLeScanCallback);
                if (mGatt == null)
                    offScan();
            }
        }, SCAN_PERIOD);

        mBluetoothAdapter.startLeScan(mLeScanCallback);

    }
    else
    {
        mBluetoothAdapter.stopLeScan(mLeScanCallback);
    }
}