3

検出されたデバイスから1 秒ごと ( ) の Bluetooth 信号強度 (rssi) を表示しようとしていますが、 Receiver Lifecycleのため、複数回Timer()呼び出すことができませんでした。onRecive()

RSSI を更新する方法 (アイデア)、または信号を毎秒測定する他の方法が必要ですか? デバイスが接続されている場合は簡単ですか?

アプリは常に一定の値を与えます:

デバイス名 2b:3c:d5:6c:3x:0X 40 デシベル

メソッドに保存されたアプリの一部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";

        }

}};
4

1 に答える 1

2

RSSI 値は、デバイス検出スキャン中にのみ取得できます。( Bluetooth 検出と接続)

「デバイスが接続されている方が簡単ですか?」したがって、Android ドキュメントでは、「既にデバイスとの接続を保持している場合、検出を実行すると、接続に使用できる帯域幅が大幅に減少する可能性があるため、接続中に検出を実行しないでください。」

本当に1秒ごとに問い合わせる必要がありますか? 電池の消費が激しい…

定期的に対策する必要があるので、AlarmManagerやCountDownTimerを使ってみませんか?

あなたの特定のケースでは、無期限に繰り返す可能性があるため、AlarmManager を使用する必要があると思います。たとえば、何かを毎秒 10 秒間実行したい場合は、CountDownTimer を使用します。

于 2013-07-25T15:45:55.917 に答える