Get bluetooth signal strength

后端 未结 4 1266
面向向阳花
面向向阳花 2020-12-01 01:09

I want to get the Bluetooth signal strength of an another device which connected to my phone,

How can I get the Bluetooth signal strength?

I

4条回答
  •  盖世英雄少女心
    2020-12-01 01:12

    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.

    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.

    Note that not all bluetooth hardware supports RSSI.

    Also Related: Android IRC Office Hours Question About Android Bluetooth RSSI here is example

    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();
            }
        }
    };
    

提交回复
热议问题