【问题标题】:Reading RSSI value of connected Bluetooth Low Energy device in Android Studio在 Android Studio 中读取已连接蓝牙低功耗设备的 RSSI 值
【发布时间】:2015-10-22 08:36:03
【问题描述】:

我正在 Android Studio 中处理一个 BLE 项目,并想读取我已经连接到的设备的 RSSI 值。到目前为止,我能够通过 LE Scan 发现新设备并从那里获取它们的 RSSI。但是,一旦我连接到设备,我就无法再运行扫描并获取 RSSI。

这是在连接到其中一个设备之前发现新设备的代码。但不确定它与我的问题有多大关系:

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();
                }
            }
        });
    }
};

提前致谢

【问题讨论】:

  • 你在配对吗?

标签: android android-studio bluetooth bluetooth-lowenergy rssi


【解决方案1】:

您必须使用 readRemoteRssi() 异步调用,然后使用回调获取 RSSI 值。 https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()

如这里详述,https://stackoverflow.com/a/20236561

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-04
    • 2013-11-17
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多