我的灯塔在didRangeBeaconsInRegion几秒后消失,但我靠近我的灯塔

时间:2017-10-12 07:21:47

标签: android ibeacon beacon altbeacon

注意: 我检查了多个设备仍然没有任何改进,我使我的信标频率达到2000毫秒但仍然面临这个问题

我正面临一个问题,信标检测稳定几秒钟,但之后它消失了,然后它检测到信标。我对这一个建议和代码示例感到震惊!!

代码

    this.beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.setForegroundScanPeriod(500);
    beaconManager.setForegroundBetweenScanPeriod(500);
    enableBackgroundMode(true);
    beaconManager.setAndroidLScanningDisabled(true);
    this.beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    this.beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(EDDYSTONE_UID_LAYOUT));
    this.beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(EDDYSTONE_URL_LAYOUT));
    this.beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(EDDYSTONE_TLM_LAYOUT));
    this.beaconManager.setDebug(true);
    this.beaconManager.bind(this);




   this.beaconManager.addRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            Log.e(TAG, "beacons size=>" + beacons.size());

            if (beacons.size() > 0) {
               //my code 
             }
  }
 });

logcat的:

10-12 12:33:48.381 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:49.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:50.356 12357-12881/com.mypackageName.android D/RangeState: adding id1: 87f8acb5-9ad0-29a7-204c-f080e2b55c0d id2: 10 id3: 1 to existing range for: org.altbeacon.beacon.service.RangedBeacon@26eeaf3b
10-12 12:33:50.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:51.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:52.381 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:52.391 12357-12880/com.mypackageName.android D/RangeState: adding id1: 87f8acb5-9ad0-29a7-204c-f080e2b55c0d id2: 10 id3: 1 to existing range for: org.altbeacon.beacon.service.RangedBeacon@26eeaf3b
10-12 12:33:53.381 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:54.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:54.396 12357-12880/com.mypackageName.android D/RangeState: adding id1: 87f8acb5-9ad0-29a7-204c-f080e2b55c0d id2: 10 id3: 1 to existing range for: org.altbeacon.beacon.service.RangedBeacon@26eeaf3b
10-12 12:33:55.381 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:56.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:57.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:58.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:33:59.381 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:34:00.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:34:01.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}
10-12 12:34:02.376 12357-12357/com.mypackageName.android D/Callback: attempting callback via global broadcast intent: ComponentInfo{com.mypackageName.android/org.altbeacon.beacon.BeaconIntentProcessor}

1 个答案:

答案 0 :(得分:1)

尝试删除这些行:

beaconManager.setForegroundScanPeriod(500);
beaconManager.setForegroundBetweenScanPeriod(500);

如果没有这些行(使用默认设置),库将在前台不断扫描。如果存在这些线路,它一次只能扫描半秒,这样很可能会丢失信标的传输并导致检测中的丢失。