gpt4 book ai didi

Android:每秒更新蓝牙rssi

转载 作者:太空狗 更新时间:2023-10-29 13:30:20 25 4
gpt4 key购买 nike

我正在尝试显示检测到的设备的蓝牙信号强度 (rssi) 每秒钟 (Timer()) 但我无法多次调用 onRecive()次因为Receiver Lifecycle .

我需要一种方法(想法)来刷新 RSSI,还是需要某种其他方法来每秒测量一个信号?如果设备已连接,是否更容易?

App 总是给出一个常量值:

DeviceName 2b:3c:d5:6c:3x:0X 40 db

部分应用存储在Timer()方法中:

    BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
// Add the name and address to an array adapter to show in a ListView

msg = device.getName() + " " + device.getAddress() + " " +rssi+ " db";

}

}};

最佳答案

您只能在设备发现扫描期间获取 RSSI 值。 ( Bluetooth Discovery vs Connection )

“如果设备连接起来会更容易吗?”相应地与android文档:“如果您已经与设备保持连接,那么执行发现会显着减少可用于连接的带宽,因此您不应在连接时执行发现。”

你真的需要每1秒执行一次查询吗?会消耗大量电池...

既然需要定期执行测量,为什么不使用 AlarmManager 或 CountDownTimer?

在您的具体情况下,我相信您应该使用 AlarmManager,因为它可以无限期地重复。例如,如果您希望某些东西每秒执行 10 秒,请使用 CountDownTimer。

关于Android:每秒更新蓝牙rssi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16252242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com