且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取蓝牙信号强度

更新时间:2022-05-07 23:23:27

为了让您可以检查蓝牙RSSI信号,可以读取RSSI连接的设备,或执行一个蓝牙发现,检查RSSI的附近任何设备。

To get the signal you can check bluetooth RSSI, you can read RSSI for connected devices, or perform a bluetooth discovery to check the RSSI for any nearby devices.

基本上是一个蓝牙的发现是一个广播范围内的所有站来响应。由于每个设备respons回来了,Android的触发了一个ACTION_FOUND意图。在此意向,你可以getExtra EXTRA_RSSI获得RSSI。

Basically a bluetooth discovery is a broadcast to all stations within range to respond back. As each devices respons back, Android fires off an ACTION_FOUND intent. Within this intent you can getExtra EXTRA_RSSI to obtain the RSSI.

请注意,并非所有的蓝牙硬件支持RSSI。

Note that not all bluetooth hardware supports RSSI.

也有关系:Android IRC办公时间问题关于Android的蓝牙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(getApplicationContext(),"  RSSI: " + rssi + "dBm", Toast.LENGTH_SHORT).show();
        }
    }
};