Android Java 蓝牙 RSSI 信号强度
Android Java Bluetooth RSSI signal strength
我对 RSSI 有疑问。我已经查看了互联网上的资源。但是所有代码都不起作用,或者我不知道这样做的方式。只是我想接收通过蓝牙连接的设备的信号强度。另外,我需要使用任何权限吗?你能解释一下所有的细节吗?我的代码如下。
private final BroadcastReceiver receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
Toast.makeText(BtControl.this," RSSI: " + rssi + "dBm", Toast.LENGTH_SHORT).show();
}
}
};
registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
您应该注册 ACTION_FOUND
行动。将您的 registerreceiver 代码更改为以下内容。
registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
还要确保您在清单文件中声明了 BLUETOOTH_ADMIN
权限。
我对 RSSI 有疑问。我已经查看了互联网上的资源。但是所有代码都不起作用,或者我不知道这样做的方式。只是我想接收通过蓝牙连接的设备的信号强度。另外,我需要使用任何权限吗?你能解释一下所有的细节吗?我的代码如下。
private final BroadcastReceiver receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
Toast.makeText(BtControl.this," RSSI: " + rssi + "dBm", Toast.LENGTH_SHORT).show();
}
}
};
registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
您应该注册 ACTION_FOUND
行动。将您的 registerreceiver 代码更改为以下内容。
registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
还要确保您在清单文件中声明了 BLUETOOTH_ADMIN
权限。