dor*_*sef 3 android bluetooth rssi bluetooth-lowenergy android-studio
我正在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();
}
}
});
}
};
Run Code Online (Sandbox Code Playgroud)
提前致谢
您必须使用readRemoteRssi()异步调用,然后使用回调获取RSSI值。https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()
如此处详述,https://stackoverflow.com/a/20236561
| 归档时间: |
|
| 查看次数: |
11206 次 |
| 最近记录: |