Reading RSSI value of connected Bluetooth Low Energy device in Android Studio

爷,独闯天下 提交于 2019-12-22 10:09:03

问题


I am working on a BLE project in Android Studio and would like to read the RSSI value of a device which I have already connected to. So far I was able to discover new devices via LE Scan and get their RSSI from there. However, once I connect to a device I can no longer run a scan and get the RSSI.

This is the code for discovering new devices before connecting to one of them. Not sure how relevant it is to my question though:

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() {
                mLeDeviceListAdapter.addDevice(device, rssi);
                //mLeDeviceListAdapter.notifyDataSetChanged();
                try {
                    mLeDeviceListAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
};

Thanks in advance


回答1:


You have to use the readRemoteRssi() Async Call and then get the RSSI value using the Callback. https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()

As detailed here, https://stackoverflow.com/a/20236561



来源:https://stackoverflow.com/questions/33276664/reading-rssi-value-of-connected-bluetooth-low-energy-device-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!