代码之家  ›  专栏  ›  技术社区  ›  Ben Sam

如何发现一定距离内的设备

  •  0
  • Ben Sam  · 技术社区  · 8 年前

    如以下线程所述: How to find the devices in the range by using bluetooth?

    android应用程序可以获取范围内的设备列表(支持蓝牙)

    我的问题是,是否有任何方法将发现范围限制在某个半径,例如1米?

    谢谢 本

    1 回复  |  直到 8 年前
        1
  •  0
  •   Diego D.    8 年前

    你可以使用 BluetoothDevice.EXTRA_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)) {
                short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
                System.out.println("RSSI: " + rssi + "dBm");
            }
        }
    };
    

    您获得的值为 dBm . A. 非常接近 根据设备的不同(内置蓝牙设备、天线、设备的实际方向),设备的rssi大约在-20 dBm到-40 dBm之间。您可以测试得到的值,以定义1米的平均“dBm范围”。该值越接近0,接收到的信号越强。