在前台进行设备扫描时,有什么方法可以改善使用altbeacon开始检测信标的情况?

时间:2019-04-18 23:15:14

标签: android altbeacon ibeacon-android

我的应用程序中有两个片段。第二个片段具有在前景中扫描信标的配置,并且我已经设置它应在onResume()中绑定信标管理器,并通过停止测距和删除通知程序来取消绑定onPause()。当我从第一个片段移动到第二个片段时,扫描将开始,它将立即检测到信标而没有任何延迟。但是,有时信标收集结果为0会导致大约6到18秒的延迟。以前,我认为logcat消息“因为这是Android N,所以没有停止扫描,因此我们一次至少扫描6秒钟。”与延迟有关,但是我再次进行了测试,发现这不是问题的原因。通常问题是发生的,尤其是当我移回第一个片段,然后再次移至第二个片段,并以不到十秒的速度如此快地重复相同的步骤三或四次时,问题就会出现并且无法检测到任何信标立即。我了解有一个扫描周期可能不会检测到一些附近的信标的可能性,但我不认为延迟是因为这样,因为通常我无法在一个或两个周期内看到任何附近的信标,因为它们接近我。

这是第二个片段的信标管理器配置代码:

@Override
public void onResume() {
    super.onResume();
    SystemRequirementsChecker.checkWithDefaultDialogs(getActivity());
    region = new Region("myRegion", Identifier.parse("1495B423-7D70-4D98-9885-51ED275B8378"), Identifier.fromInt(14650), Identifier.fromInt(4477));
    beaconManager1 = BeaconManager.getInstanceForApplication(getApplicationContext());
    beaconManager1.getBeaconParsers().clear();
    beaconManager1.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager1.setDebug(true);
    beaconManager1.bind(this);

}

@Override
public void onPause() {
    try {
        beaconManager1.stopRangingBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    beaconManager1.unbind(this);
    beaconManager1.removeRangeNotifier(rangeNotifier);
    super.onPause();
}

@Override
public void onBeaconServiceConnect() {
    beaconManager1.removeAllRangeNotifiers();
    rangeNotifier = new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
            Log.d("Collection: ", "size = " + collection.size());
            Log.d("GetRegion: ", region.getId1().toString());
            if (collection.size() > 0) {
                progressBar.setVisibility(View.GONE);
                btnViewAllItems.setVisibility(View.VISIBLE);
                Log.d("Collection: ", "size = " + collection.size());
                count = 0;
                userInsideHSC = true;
            } else {
                startCount();
            }
        }
    };

    try {
        beaconManager1.startRangingBeaconsInRegion(region);
        beaconManager1.addRangeNotifier(rangeNotifier);
    } catch (RemoteException e) {

    }
}

@Override
public Context getApplicationContext() {
    return getActivity().getApplicationContext();
}

@Override
public void unbindService(ServiceConnection serviceConnection) {
    getActivity().unbindService(serviceConnection);
}

@Override
public boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) {
    return getActivity().bindService(intent, serviceConnection, i);
}

我正在使用的设备是运行Android 9的Samsung Galaxy Note 8,而altbeacon的版本是2.16.1

LogCat:

2019-04-20 12:15:13.172 11452-11452 D/ViewRootImpl@71ce719[NewHomeActivity]: ViewPostIme pointer 1
2019-04-20 12:15:13.186 11452-11452 D/ScrollView: initGoToTop
2019-04-20 12:15:13.218 11452-11452 D/BeaconParser: Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24
2019-04-20 12:15:13.219 11452-11452 W/BeaconManager: Disabling ScanJobs on Android 8+ may disable delivery of beacon callbacks in the background unless a foreground service is active.
2019-04-20 12:15:13.219 11452-11452 D/BeaconManager: This consumer is not bound.  Binding now: CategoryDetailsFragment{bb6c68a #13 id=0x7f080089}
2019-04-20 12:15:13.219 11452-11452 D/BeaconManager: Binding to service
2019-04-20 12:15:13.225 11452-11452 D/BeaconManager: consumer count is now: 1
2019-04-20 12:15:13.247 11452-11452 D/ViewRootImpl@71ce719[NewHomeActivity]: Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x1 surface={valid=true 488142176256} changed=false
2019-04-20 12:15:13.249 11452-11452 D/ScrollView:  onsize change changed 
2019-04-20 12:15:13.262 11452-11452 I/CycledLeScanner: Using Android O scanner
2019-04-20 12:15:13.263 11452-11452 I/BeaconService: beaconService version 2.16.1 is starting up on the main process
2019-04-20 12:15:13.263 11452-11452 D/BeaconLocalBroadcastProcessor: Register calls: global=12 instance=1
2019-04-20 12:15:13.269 11452-11452 D/ModelSpecificDistanceCalculator: Finding best distance calculator for 9, PPR1.180610.011, SM-N950F, samsung
2019-04-20 12:15:13.269 11452-11452 D/AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.269 11452-11452 D/AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.270 11452-11452 D/AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.270 11452-11452 W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
2019-04-20 12:15:13.270 11452-11452 D/ModelSpecificDistanceCalculator: Finding best distance calculator for 9, PPR1.180610.011, SM-N950F, samsung
2019-04-20 12:15:13.270 11452-11452 D/AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.270 11452-11452 D/AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.270 11452-11452 D/AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to samsung;SM-N950F;PPR1.180610.011;9
2019-04-20 12:15:13.270 11452-11452 W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
2019-04-20 12:15:13.271 11452-11452 D/BeaconService: No org.altbeacon.beacon.SimulatedScanData class exists.
2019-04-20 12:15:13.271 11452-11452 I/BeaconService: binding
2019-04-20 12:15:13.276 11452-11452 D/BeaconManager: we have a connection to the service now
2019-04-20 12:15:13.276 11452-11452 D/BeaconManager: Not synchronizing settings to service, as it is in the same process
2019-04-20 12:15:13.277 11452-11452 D/BeaconManager: updating background flag to false
2019-04-20 12:15:13.277 11452-11452 D/BeaconManager: updating scan period to 1100, 1000
2019-04-20 12:15:13.278 11452-11452 D/BeaconManager: callback packageName: com.hsc.gutech.hscapp
2019-04-20 12:15:13.279 11452-11452 I/BeaconService: set scan intervals received
2019-04-20 12:15:13.279 11452-11452 D/CycledLeScanner: Set scan periods called with 1100, 1000 Background mode must have changed.
2019-04-20 12:15:13.279 11452-11452 D/CycledLeScanner: We are not in the background.  Cancelling wakeup alarm
2019-04-20 12:15:13.279 11452-11452 D/CycledLeScanner: cancel wakeup alarm: null
2019-04-20 12:15:13.287 11452-11452 D/CycledLeScanner: Set a wakeup alarm to go off in 9223372036703844447 ms: PendingIntent{bd5e63a: android.os.BinderProxy@fb4241}
2019-04-20 12:15:13.288 11452-11452 I/BeaconService: start ranging received
2019-04-20 12:15:13.288 11452-11452 D/BeaconService: Currently ranging 1 regions.
2019-04-20 12:15:13.288 11452-11452 D/CycledLeScanner: start called
2019-04-20 12:15:13.288 11452-11452 D/CycledLeScanner: starting a new scan cycle
2019-04-20 12:15:13.289 11452-11452 D/CycledLeScanner: starting a new bluetooth le scan
2019-04-20 12:15:13.291 11452-11452 D/CycledLeScannerForLollipop: starting a scan in SCAN_MODE_LOW_LATENCY
2019-04-20 12:15:13.291 11452-11452 D/CycledLeScannerForLollipop: Using a non-empty scan filter since this is Samsung 8.1+
2019-04-20 12:15:13.291 11452-11452 D/ScanFilterUtils: Set up a scan filter: BluetoothLeScanFilter [mDeviceName=null, mDeviceAddress=null, mUuid=null, mUuidMask=null, mServiceDataUuid=null, mServiceData=null, mServiceDataMask=null, mManufacturerId=4c, mManufacturerData=02 15, mManufacturerDataMask=FF FF]
2019-04-20 12:15:13.291 11452-11452 D/CycledLeScannerForLollipop: Making new Android L scanner
2019-04-20 12:15:13.292 11452-11452 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:13.292 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1100 milliseconds
2019-04-20 12:15:13.292 11452-11452 D/CycledLeScanner: Scan started
2019-04-20 12:15:13.292 11452-11452 D/CycledLeScanner: Set scan periods called with 1100, 1000 Background mode must have changed.
2019-04-20 12:15:13.292 11452-11452 D/CycledLeScanner: We are not in the background.  Cancelling wakeup alarm
2019-04-20 12:15:13.292 11452-11452 D/CycledLeScanner: cancel wakeup alarm: PendingIntent{bd5e63a: android.os.BinderProxy@fb4241}
2019-04-20 12:15:13.293 11452-12036 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:13.295 11452-12036 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:13.295 11452-12036 D/BluetoothLeScanner: Start Scan with callback
2019-04-20 12:15:13.296 11452-11662 D/BluetoothLeScanner: onScannerRegistered() - status=6 scannerId=-1 mScannerId=0
2019-04-20 12:15:13.301 11452-11452 D/CycledLeScanner: Set a wakeup alarm to go off in 9223372036703844434 ms: PendingIntent{bd5e63a: android.os.BinderProxy@fb4241}
2019-04-20 12:15:14.293 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 99 milliseconds
2019-04-20 12:15:14.392 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1 milliseconds
2019-04-20 12:15:14.393 11452-11452 D/CycledLeScanner: Done with scan cycle
2019-04-20 12:15:14.394 11452-11452 D/ScanHelper: Beacon simulator not enabled
2019-04-20 12:15:14.395 11452-11452 D/ScanHelper: Calling ranging callback
2019-04-20 12:15:14.395 11452-11452 D/Callback: attempting callback via local broadcast intent: org.altbeacon.beacon.range_notification
2019-04-20 12:15:14.401 11452-11452 D/CycledLeScanner: Not stopping scan because this is Android N and we keep scanning for a minimum of 6 seconds at a time. We will stop in 4894 millisconds.
2019-04-20 12:15:14.401 11452-11452 D/CycledLeScanner: Normalizing between scan period from 1000 to -274
2019-04-20 12:15:14.401 11452-11452 D/CycledLeScanner: starting a new scan cycle
2019-04-20 12:15:14.401 11452-11452 D/CycledLeScanner: We are already scanning and have been for 1111 millis
2019-04-20 12:15:14.402 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1100 milliseconds
2019-04-20 12:15:14.402 11452-11452 D/CycledLeScanner: Scan started
2019-04-20 12:15:14.402 11452-11452 D/IntentHandler: got ranging data
2019-04-20 12:15:14.402 11452-11452 D/Collection:: size = 0
2019-04-20 12:15:14.403 11452-11452 D/GetRegion:: 1495b423-7d70-4d98-9885-51ed275b8378
2019-04-20 12:15:15.403 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 99 milliseconds
2019-04-20 12:15:15.502 11452-11452 D/CycledLeScanner: Done with scan cycle
2019-04-20 12:15:15.503 11452-11452 D/ScanHelper: Beacon simulator not enabled
2019-04-20 12:15:15.504 11452-11452 D/ScanHelper: Calling ranging callback
2019-04-20 12:15:15.504 11452-11452 D/Callback: attempting callback via local broadcast intent: org.altbeacon.beacon.range_notification
2019-04-20 12:15:15.508 11452-11452 D/CycledLeScanner: Not stopping scan because this is Android N and we keep scanning for a minimum of 6 seconds at a time. We will stop in 3784 millisconds.
2019-04-20 12:15:15.508 11452-11452 D/CycledLeScanner: Normalizing between scan period from 1000 to 719
2019-04-20 12:15:15.509 11452-11452 D/CycledLeScannerForLollipop: This is Android L, but we last saw a beacon only 2635 ago, so we will not keep scanning in background.
2019-04-20 12:15:15.509 11452-11452 D/CycledLeScannerForLollipop: Waiting to start full Bluetooth scan for another 719 milliseconds
2019-04-20 12:15:15.509 11452-11452 D/IntentHandler: got ranging data
2019-04-20 12:15:15.510 11452-11452 D/Collection:: size = 0
2019-04-20 12:15:15.510 11452-11452 D/GetRegion:: 1495b423-7d70-4d98-9885-51ed275b8378
2019-04-20 12:15:16.229 11452-11452 D/CycledLeScanner: starting a new scan cycle
2019-04-20 12:15:16.230 11452-11452 D/CycledLeScanner: We are already scanning and have been for 2939 millis
2019-04-20 12:15:16.230 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1100 milliseconds
2019-04-20 12:15:16.230 11452-11452 D/CycledLeScanner: Scan started
2019-04-20 12:15:17.232 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 99 milliseconds
2019-04-20 12:15:17.331 11452-11452 D/CycledLeScanner: Done with scan cycle
2019-04-20 12:15:17.332 11452-11452 D/ScanHelper: Beacon simulator not enabled
2019-04-20 12:15:17.332 11452-11452 D/ScanHelper: Calling ranging callback
2019-04-20 12:15:17.333 11452-11452 D/Callback: attempting callback via local broadcast intent: org.altbeacon.beacon.range_notification
2019-04-20 12:15:17.338 11452-11452 D/CycledLeScanner: Not stopping scan because this is Android N and we keep scanning for a minimum of 6 seconds at a time. We will stop in 1955 millisconds.
2019-04-20 12:15:17.338 11452-11452 D/CycledLeScanner: Normalizing between scan period from 1000 to 989
2019-04-20 12:15:17.339 11452-11452 D/CycledLeScannerForLollipop: This is Android L, but we last saw a beacon only 4465 ago, so we will not keep scanning in background.
2019-04-20 12:15:17.339 11452-11452 D/CycledLeScannerForLollipop: Waiting to start full Bluetooth scan for another 989 milliseconds
2019-04-20 12:15:17.340 11452-11452 D/IntentHandler: got ranging data
2019-04-20 12:15:17.340 11452-11452 D/Collection:: size = 0
2019-04-20 12:15:17.341 11452-11452 D/GetRegion:: 1495b423-7d70-4d98-9885-51ed275b8378
2019-04-20 12:15:18.330 11452-11452 D/CycledLeScanner: starting a new scan cycle
2019-04-20 12:15:18.331 11452-11452 D/CycledLeScanner: We are already scanning and have been for 5041 millis
2019-04-20 12:15:18.331 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1100 milliseconds
2019-04-20 12:15:18.331 11452-11452 D/CycledLeScanner: Scan started
2019-04-20 12:15:19.333 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 98 milliseconds
2019-04-20 12:15:19.431 11452-11452 D/CycledLeScanner: Done with scan cycle
2019-04-20 12:15:19.432 11452-11452 D/ScanHelper: Beacon simulator not enabled
2019-04-20 12:15:19.432 11452-11452 D/ScanHelper: Calling ranging callback
2019-04-20 12:15:19.433 11452-11452 D/Callback: attempting callback via local broadcast intent: org.altbeacon.beacon.range_notification
2019-04-20 12:15:19.436 11452-11452 D/CycledLeScanner: stopping bluetooth le scan
2019-04-20 12:15:19.436 11452-11452 D/CycledLeScannerForLollipop: Stopping scan
2019-04-20 12:15:19.438 11452-12036 D/CycledLeScannerForLollipop: Stopping LE scan on scan handler
2019-04-20 12:15:19.438 11452-11452 D/CycledLeScanner: Normalizing between scan period from 1000 to 989
2019-04-20 12:15:19.439 11452-11452 D/CycledLeScannerForLollipop: This is Android L, but we last saw a beacon only 6565 ago, so we will not keep scanning in background.
2019-04-20 12:15:19.439 11452-11452 D/CycledLeScannerForLollipop: Waiting to start full Bluetooth scan for another 989 milliseconds
2019-04-20 12:15:19.439 11452-11452 D/IntentHandler: got ranging data
2019-04-20 12:15:19.440 11452-11452 D/Collection:: size = 0
2019-04-20 12:15:19.440 11452-11452 D/GetRegion:: 1495b423-7d70-4d98-9885-51ed275b8378
2019-04-20 12:15:19.443 11452-12036 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:19.443 11452-12036 D/BluetoothLeScanner: could not find callback wrapper
2019-04-20 12:15:20.429 11452-11452 D/CycledLeScanner: starting a new scan cycle
2019-04-20 12:15:20.433 11452-11452 D/CycledLeScanner: starting a new bluetooth le scan
2019-04-20 12:15:20.438 11452-11452 D/CycledLeScannerForLollipop: starting a scan in SCAN_MODE_LOW_LATENCY
2019-04-20 12:15:20.438 11452-11452 D/CycledLeScannerForLollipop: Using a non-empty scan filter since this is Samsung 8.1+
2019-04-20 12:15:20.439 11452-11452 D/ScanFilterUtils: Set up a scan filter: BluetoothLeScanFilter [mDeviceName=null, mDeviceAddress=null, mUuid=null, mUuidMask=null, mServiceDataUuid=null, mServiceData=null, mServiceDataMask=null, mManufacturerId=4c, mManufacturerData=02 15, mManufacturerDataMask=FF FF]
2019-04-20 12:15:20.440 11452-11452 D/CycledLeScanner: Waiting to stop scan cycle for another 1100 milliseconds
2019-04-20 12:15:20.440 11452-11452 D/CycledLeScanner: Scan started
2019-04-20 12:15:20.442 11452-12036 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:20.447 11452-12036 D/BluetoothAdapter: STATE_ON
2019-04-20 12:15:20.447 11452-12036 D/BluetoothLeScanner: Start Scan with callback
2019-04-20 12:15:20.456 11452-11662 D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=31 mScannerId=0
2019-04-20 12:15:20.558 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.562 11452-12039 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.563 11452-12039 D/BeaconParser: Processing pdu type FF: 0201061aff4c000215e1f54e021e2344e09c3d512eb56adec900640064b90000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.563 11452-12039 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.564 11452-12039 D/BeaconParser: Bytes are: 0201061aff4c000215e1f54e021e2344e09c3d512eb56adec900640064b90000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.569 11452-12039 D/ScanHelper: Beacon packet detected for: id1: e1f54e02-1e23-44e0-9c3d-512eb56adec9 id2: 100 id3: 100 with rssi -73
2019-04-20 12:15:20.570 11452-12039 D/ScanHelper: beacon detected : id1: e1f54e02-1e23-44e0-9c3d-512eb56adec9 id2: 100 id3: 100
2019-04-20 12:15:20.571 11452-12039 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.571 11452-12039 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: e1f54e02-1e23-44e0-9c3d-512eb56adec9 id2: 100 id3: 100
2019-04-20 12:15:20.579 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.584 11452-12040 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.585 11452-12040 D/BeaconParser: Processing pdu type FF: 0201061aff4c0002155d060e0d8b1643eb83e768d40cc36e99c3d18f2bc20000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.585 11452-12040 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.586 11452-12040 D/BeaconParser: Bytes are: 0201061aff4c0002155d060e0d8b1643eb83e768d40cc36e99c3d18f2bc20000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.591 11452-12040 D/ScanHelper: Beacon packet detected for: id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 50129 id3: 36651 with rssi -86
2019-04-20 12:15:20.592 11452-12040 D/ScanHelper: beacon detected : id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 50129 id3: 36651
2019-04-20 12:15:20.594 11452-12040 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.595 11452-12040 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 50129 id3: 36651
2019-04-20 12:15:20.610 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.614 11452-12041 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.614 11452-12041 D/BeaconParser: Processing pdu type FF: 0201061aff4c0002156a032029db6525b912fad57af1ea8150e01758c0af0000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.616 11452-12041 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.616 11452-12041 D/BeaconParser: Bytes are: 0201061aff4c0002156a032029db6525b912fad57af1ea8150e01758c0af0000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.620 11452-12041 D/ScanHelper: Beacon packet detected for: id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 57367 id3: 22720 with rssi -95
2019-04-20 12:15:20.621 11452-12041 D/ScanHelper: beacon detected : id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 57367 id3: 22720
2019-04-20 12:15:20.621 11452-12041 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.622 11452-12041 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 57367 id3: 22720
2019-04-20 12:15:20.627 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.629 11452-12042 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.632 11452-12042 D/BeaconParser: Processing pdu type FF: 0201061aff4c0002156a032029db6525b912fad57af1ea81503e6184bdaf0000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.632 11452-12042 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.633 11452-12042 D/BeaconParser: Bytes are: 0201061aff4c0002156a032029db6525b912fad57af1ea81503e6184bdaf0000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.641 11452-12042 D/ScanHelper: Beacon packet detected for: id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 15969 id3: 33981 with rssi -98
2019-04-20 12:15:20.642 11452-12042 D/ScanHelper: beacon detected : id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 15969 id3: 33981
2019-04-20 12:15:20.643 11452-12042 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.643 11452-12042 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: 6a032029-db65-25b9-12fa-d57af1ea8150 id2: 15969 id3: 33981
2019-04-20 12:15:20.644 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.647 11452-12043 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.647 11452-12043 D/BeaconParser: Processing pdu type FF: 0201061aff4c00021591d7e4463ac0198f35194d7a7ac4c9a771f81c49c50000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.648 11452-12043 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.648 11452-12043 D/BeaconParser: Bytes are: 0201061aff4c00021591d7e4463ac0198f35194d7a7ac4c9a771f81c49c50000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.652 11452-12043 D/ScanHelper: Beacon packet detected for: id1: 91d7e446-3ac0-198f-3519-4d7a7ac4c9a7 id2: 29176 id3: 7241 with rssi -76
2019-04-20 12:15:20.653 11452-12043 D/ScanHelper: beacon detected : id1: 91d7e446-3ac0-198f-3519-4d7a7ac4c9a7 id2: 29176 id3: 7241
2019-04-20 12:15:20.653 11452-12043 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.654 11452-12043 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: 91d7e446-3ac0-198f-3519-4d7a7ac4c9a7 id2: 29176 id3: 7241
2019-04-20 12:15:20.670 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.673 11452-12044 D/BeaconParser: Ignoring pdu type 01
2019-04-20 12:15:20.674 11452-12044 D/BeaconParser: Processing pdu type FF: 0201061aff4c0002155d060e0d8b1643eb83e768d40cc36e995092e201c20000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
2019-04-20 12:15:20.679 11452-12044 D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
2019-04-20 12:15:20.679 11452-12044 D/BeaconParser: Bytes are: 0201061aff4c0002155d060e0d8b1643eb83e768d40cc36e995092e201c20000000000000000000000000000000000000000000000000000000000000000
2019-04-20 12:15:20.684 11452-12044 D/ScanHelper: Beacon packet detected for: id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 20626 id3: 57857 with rssi -73
2019-04-20 12:15:20.685 11452-12044 D/ScanHelper: beacon detected : id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 20626 id3: 57857
2019-04-20 12:15:20.685 11452-12044 D/ScanHelper: looking for ranging region matches for this beacon
2019-04-20 12:15:20.686 11452-12044 D/ScanHelper: This region (id1: 1495b423-7d70-4d98-9885-51ed275b8378 id2: 14650 id3: 4477) does not match beacon: id1: 5d060e0d-8b16-43eb-83e7-68d40cc36e99 id2: 20626 id3: 57857
2019-04-20 12:15:20.725 11452-11452 D/CycledLeScannerForLollipop: got record
2019-04-20 12:15:20.734 11452-11463 I/c.gutech.hscap: Background concurrent copying GC freed 130403(5MB) AllocSpace objects, 4(80KB) LOS objects, 70% free, 2MB/8MB, paused 341us total 105.955ms
2019-04-20 12:15:20.736 11452-11452 D/CycledLeScannerForLollipop: got record

1 个答案:

答案 0 :(得分:1)

在Android 8+上,该库使用JobScheduler安排信标扫描。如果在应用程序处于前台时绑定到BeaconManager,它将调度立即 ScanJob。如果然后解除绑定,它将取消此立即扫描作业。下次绑定时,它会安排另一个立即 ScanJob。

这是一个昂贵的过程,使用了大量电话资源。因此,该库旨在禁止在10秒内重新启动ScanJob的尝试。如果您尝试在同一10秒钟内两次启动ScanJob,则下次启动将被延迟,可能会导致您看到的症状。

如果您要开发的应用程序能够在Fragment之间快速移动时迅速开始扫描,则会遇到此问题。

如果您不能忍受延迟,那么最简单的解决方案是将扫描开始/停止移至更高级别的代码,因此在出现片段时它已经开始。通常在自定义Application类或实现BeaconConsumer的POJO中执行此操作。如果选择POJO路由,请确保将BeaconConsumer的所有方法链接到Android Context对象上的等效方法。