検出されたデバイスから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";
}
}};