安卓:每秒更新蓝牙信号强度(RSSI)

3
我正在尝试每秒显示检测到设备的蓝牙信号强度(rssi)(Timer()),但由于接收器生命周期,我无法多次调用onRecive()
我需要一种方法(想法)来刷新RSSI,或者其他一些方法来每秒测量信号?如果设备连接,是否更容易?
应用程序始终提供恒定值:

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";

        }

}};

你找到任何解决方案了吗? - naima
1个回答

2
只能在设备发现扫描期间获取RSSI值。(来自Bluetooth Discovery vs Connection
“如果设备已连接,是否更容易?”根据Android文档:“如果您已经与设备建立连接,则执行发现会显着减少连接可用的带宽,因此您不应在连接时执行发现。”
您真的需要每1秒执行一次查询吗?这将消耗很多电池...
由于您需要定期执行测量,为什么不使用AlarmManager或CountDownTimer?
在您的特定情况下,我认为您应该使用AlarmManager,因为它可以无限重复。例如,如果您想每秒执行一次某个操作10秒钟,请使用CountDownTimer。

如果您实现了BluetoothGatt回调,您可以在连接打开时随时读取rssi。 - Alan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接