我试图从检测到的设备上显示蓝牙信号强度(rssi)evry second(Timer()
),但由于Receiver Lifecycle我无法多次呼叫onRecive()
。Android:每秒钟更新蓝牙rssi
我需要一种方法(想法)来刷新RSSI,或者其他方式来每秒钟测量一次信号? 设备连接更容易吗?
应用给出了一个恒定的值始终:
的DeviceName 2B:3C:D5:6C:3×:0X40分贝存储在
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";
}
}};