更高效地检测信标

Detecting beacons more efficiency

我使用这些方法来检测信标

 @Override
    public void onBeaconServiceConnect() {

        BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.setRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                Log.i("MainA","-------------------------------");
                for (Beacon beacon : beacons) {
                    Log.i("MainActivity", "I see a beacon"+beacon.getId1()+" Major: " + beacon.getId2()+" Minor: "+beacon.getId3());
                }
                Log.i("MainA","-------------------------------");
            }
        });

        try {
            beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        } catch (RemoteException e) {    }
    }

我正在使用两个信标,一个estimoe信标和一个用bluez模拟的虚拟信标。输出中信标的 UUID 是 changed.The 检测有效,但有时正如您在输出中看到的那样,调用 onBeaconServiceConnect 函数时仅检测到一个信标,甚至 none 个。我知道我可以等待 10 秒左右,如果不再检测到信标,我可以假设它不再在该区域,但是是否有一种有效的方法可以在检测到或不再检测到信标时尽快检测?

-------------------------------
04-24 17:10:33.021 2041-3467/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:33.021 2041-3467/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:33.021 2041-3467/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:33.101 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:33.101 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:34.161 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.161 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.161 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:34.171 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:34.171 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.181 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.181 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.181 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:34.231 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:34.341 2041-3510/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:34.351 2041-3510/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:34.351 2041-3510/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:35.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.411 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:35.461 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:35.461 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.461 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:35.511 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:35.531 2041-3562/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:35.531 2041-3562/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:36.011 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:36.011 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:36.641 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.641 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.641 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:36.651 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:36.651 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.651 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:36.701 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:36.711 2041-3628/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:36.711 2041-3628/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:36.711 2041-3628/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:37.821 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.821 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.821 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:37.841 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:37.841 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.841 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.841 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.841 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:37.891 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:37.901 2041-3681/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:37.901 2041-3681/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:39.071 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.071 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.071 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:39.091 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:39.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.111 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.111 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.111 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:39.161 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:39.171 2041-3724/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:39.171 2041-3724/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:40.321 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.321 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.321 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:40.401 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:40.401 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.401 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:40.451 2041-2054/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:40.461 2041-3770/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:40.461 2041-3770/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:40.761 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:40.761 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:41.591 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.591 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.591 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:41.661 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:41.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.661 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:41.711 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:41.721 2041-3819/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:41.721 2041-3819/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:41.721 2041-3819/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:42.861 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.871 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.871 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:42.881 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:42.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:42.941 2041-2054/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:43.071 2041-3865/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:43.071 2041-3865/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:43.631 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:43.631 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:44.111 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.111 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.111 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:44.131 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:44.131 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.131 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.131 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.131 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:44.181 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:44.201 2041-3927/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:44.201 2041-3927/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:44.201 2041-3927/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:44.621 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:44.621 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:45.321 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.321 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.321 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:45.331 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:45.331 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.331 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.331 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.341 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:45.381 2041-2054/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:45.401 2041-4042/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:45.401 2041-4042/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:45.401 2041-4042/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:45.531 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:45.531 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:46.511 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.511 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.511 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:46.521 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:46.521 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.521 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.521 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.521 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:46.571 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:46.581 2041-4080/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:46.581 2041-4080/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:46.581 2041-4080/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:47.701 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.701 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.701 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:47.711 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:47.721 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.721 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.721 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.721 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:47.771 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:47.781 2041-4116/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:47.781 2041-4116/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:48.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.891 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:48.911 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:48.911 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.911 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.921 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.921 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:48.961 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:48.971 2041-4169/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:48.971 2041-4169/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:50.081 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.081 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.081 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:50.091 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:50.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:50.151 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:50.161 2041-4218/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:50.161 2041-4218/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:51.271 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.271 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.271 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:51.281 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:51.281 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.291 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.291 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.291 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:51.331 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:51.351 2041-4281/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:51.351 2041-4281/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:51.561 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:51.561 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:52.451 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.461 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.461 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:52.461 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:52.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.471 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:52.521 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:52.571 2041-4338/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:52.571 2041-4338/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:52.571 2041-4338/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:52.871 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:52.871 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:53.191 2041-3131/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:53.191 2041-3131/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:53.671 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.671 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.671 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:53.691 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:53.691 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.691 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.691 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.691 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:53.741 2041-2053/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:53.761 2041-4376/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:53.761 2041-4376/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:53.761 2041-4376/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:53.761 2041-4376/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:54.111 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:54.111 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:54.141 2041-2053/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:54.141 2041-2053/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:54.861 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.871 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.871 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:54.881 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:54.881 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.891 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:54.931 2041-2054/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:54.951 2041-4438/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:54.951 2041-4438/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:54.951 2041-4438/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:54.951 2041-4438/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:55.081 2041-3131/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:55.081 2041-3131/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:55.431 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:55.431 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:56.071 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.071 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.071 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:56.101 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:56.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.101 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:56.151 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:56.201 2041-4523/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:56.201 2041-4523/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:56.201 2041-4523/com.example.kev.altbeacon I/MainActivity: I see a beaconhgfhgvgv-h7h5-88h9-kjh3-7554hjvv8 Major: 39749 Minor: 25488
04-24 17:10:56.201 2041-4523/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:56.721 2041-3131/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:56.721 2041-3131/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:57.341 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.341 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.341 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:57.401 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:57.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.411 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:57.451 2041-3131/com.example.kev.altbeacon D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
04-24 17:10:57.471 2041-4575/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:57.471 2041-4575/com.example.kev.altbeacon I/MainActivity: I see a beacon123456-hfhj-JJJJ-87j8-jjkzbzkf876 Major: 4369 Minor: 4369
04-24 17:10:57.471 2041-4575/com.example.kev.altbeacon I/MainA: -------------------------------
04-24 17:10:57.931 2041-2054/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:57.931 2041-2054/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:57.991 2041-3131/com.example.kev.altbeacon D/ScanRecord: parseFromBytes
04-24 17:10:57.991 2041-3131/com.example.kev.altbeacon D/ScanRecord: first manudata for manu ID
04-24 17:10:58.591 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:58.591 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:58.591 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Stop Scan
04-24 17:10:58.611 2041-2041/com.example.kev.altbeacon D/BluetoothLeScanner: Start Scan
04-24 17:10:58.611 2041-2041/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-24 17:10:58.611 2041-2041/com.example.kev.altbeacon D/Bluet

快速报告信标检测很容易——只要无线电解码数据包,您就可以报告检测。在 Android 5+ 的背景中,这正是 Android 信标库所做的。

报告不再检测到信标更难。根本问题是 无法立即知道信标何时超出范围。 信标传输不是恒定信号 - 它们在传输静默期之间脉冲分组。因此,确定不存在信标是通过查看未检测到信标数据包的某个时间间隔来确定的。

移动设备也不会 100% 检测到发送的信标数据包。无线电噪声、弱信号和冲突可能导致数据包丢失。在几米的短距离内,可能会收到 80-90% 的数据包。在 40-50 米的最大 BLE 传输范围附近的更远距离,该百分比下降到几乎为零。

因此,信标检测框架必须有一个自上次检测以来的时间间隔,该时间间隔表示从统计上讲,信标可能不再在附近。当在此间隔内未检测到信标数据包时,事件将触发。

可以缩短此间隔,但需要权衡取舍。间隔时间越短,获得错误退出回调的可能性就越大。这意味着您将获得一个退出回调,然后在下一次检测到数据包时迅速获得一个新的进入回调。

决定在触发退出之前等待信标数据包的时间很大程度上受信标数据包传输速率的影响。

最常见的传输频率是10Hz,即每秒传输10个数据包。但是许多制造商构建的信标传输频率较低,或者构建的信标可以配置为传输频率较低以节省电池电量。电池信标通常以仅 1 Hz 的传输频率配置运送。 有些信标每 5 秒或更短时间只传输一次。

Apple 的 CoreLocation 框架使用 30 秒作为用于测距和监控目的的信标区域退出间隔。在测距期间,如果在过去的一秒内未检测到信标,则报告接近 "unknown"。这是不可配置的。

Android信标库也使用 30 秒作为默认的信标区域退出间隔(这是可配置的),如果过去未检测到信标,它不会将其包含在测距列表中测距周期(可配置,但默认为 1.1 秒。)

根据显示的日志输出,Major: 39749 Minor: 25488 的信标似乎以低于 1 Hz 的低频 进行广告,或者具有较低的频率信号电平使其大部分数据包丢失。如果你提高它的传输率,检测会更可靠。

由于您使用的是 Android 信标库,您可以选择延长测距扫描间隔 使其长于默认的 1.1 秒,因此检测显得更加稳重。您可以通过调用 beaconManager.setForegroundScanInterval(5000l); 将其设置为 5 秒来执行此操作。

另一种选择是添加一个软件过滤器以记住在过去几秒内是否看到了信标然后报告它仍然可见,即使图书馆说它是不是。这样做的好处是初始检测不会减慢超过 1.1 秒。