重新启动活动时无法扫描信标

时间:2019-01-22 07:46:30

标签: android beacon altbeacon

我导入了android-beacon-library-2.15.2.aar 该库并扫描信标,

public static final String UUID = "***";
    private BeaconManager beaconManager;
    private Region defaultRegion = null;

    Button btnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnNext = findViewById(R.id.btn_next);

        defaultRegion = new Region("******", null, null, null);
        beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("***"));

        beaconManager.bind(this);

        beaconManager.setDebug(true);

        btnNext.setOnClickListener(this);

    }

@Override
    public void onBeaconServiceConnect() {

        beaconManager.addRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {

                if (collection.size() > 0){

                    Log.d("BeaconInfo","Beaconsize " + collection.size());

                }

            }
        });

        try {
            beaconManager.startRangingBeaconsInRegion(defaultRegion);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }

完成活动后

@Override
    protected void onStop() {
        super.onStop();

        beaconManager.unbind(this);

    }

因此,当我进入信标扫描活动时,我可以在第一时间收到扫描信息。 但是,当我回到之前的活动并重新进入信标扫描活动时,我看不到信标信息。

我认为beaconManager.bind(this)beaconManager.unbind(this)是信标的开始和结束。

有什么方法可以重启信标扫描吗?


Log(When I start scan at first time)
2019-01-23 09:35:59.359 22279-22279/com.example.thewell_dev.myapplication I/CycledLeScanner: Using Android O scanner
2019-01-23 09:35:59.361 22279-22279/com.example.thewell_dev.myapplication I/ScanJob: Using immediateScanJobId from manifest: 208352939
2019-01-23 09:35:59.362 22279-22279/com.example.thewell_dev.myapplication I/ScanJob: Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@f6e3a23
2019-01-23 09:35:59.362 22279-22279/com.example.thewell_dev.myapplication I/ScanJob: scanJob version 2.15.2 is starting up on the main process
2019-01-23 09:35:59.364 22279-22279/com.example.thewell_dev.myapplication W/ModelSpecificDistanceCalculator: App has no android.permission.INTERNET permission.  Cannot check for distance model updates
2019-01-23 09:35:59.410 22279-22279/com.example.thewell_dev.myapplication D/BluetoothAdapter: isLeEnabled(): ON
2019-01-23 09:35:59.415 22279-22279/com.example.thewell_dev.myapplication I/ScanJob: Scan job running for 300000 millis
2019-01-23 09:35:59.415 22279-22336/com.example.thewell_dev.myapplication D/BluetoothAdapter: isLeEnabled(): ON
2019-01-23 09:35:59.416 22279-22279/com.example.thewell_dev.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@63c81ec time:18384954
2019-01-23 09:35:59.417 22279-22294/com.example.thewell_dev.myapplication D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=16 mScannerId=0
2019-01-23 09:35:59.792 22279-22366/com.example.thewell_dev.myapplication I/ScanHelper: Non-distinct packets detected in a single scan.  Restarting scans unecessary.
2019-01-23 09:36:00.504 22279-22284/com.example.thewell_dev.myapplication I/zygote64: Do full code cache collection, code=116KB, data=86KB
2019-01-23 09:36:00.504 22279-22284/com.example.thewell_dev.myapplication I/zygote64: After code cache collection, code=88KB, data=56KB
2019-01-23 09:36:00.529 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:01.649 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 46
2019-01-23 09:36:02.755 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 49
2019-01-23 09:36:03.125 22279-22284/com.example.thewell_dev.myapplication I/zygote64: Do partial code cache collection, code=124KB, data=76KB
2019-01-23 09:36:03.125 22279-22284/com.example.thewell_dev.myapplication I/zygote64: After code cache collection, code=124KB, data=76KB
2019-01-23 09:36:03.125 22279-22284/com.example.thewell_dev.myapplication I/zygote64: Increasing code cache capacity to 512KB
2019-01-23 09:36:03.860 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 47
2019-01-23 09:36:04.965 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 47
2019-01-23 09:36:06.075 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 45
2019-01-23 09:36:07.197 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 52
2019-01-23 09:36:08.303 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 52
2019-01-23 09:36:09.416 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 54
2019-01-23 09:36:10.519 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:11.629 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 52
2019-01-23 09:36:12.731 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:14.070 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 46
2019-01-23 09:36:15.177 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 55
2019-01-23 09:36:16.284 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:17.393 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 51
2019-01-23 09:36:18.504 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:19.611 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 53
2019-01-23 09:36:20.731 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 56
2019-01-23 09:36:21.836 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 51
2019-01-23 09:36:22.948 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 46
2019-01-23 09:36:24.062 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 44
2019-01-23 09:36:25.171 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 51
2019-01-23 09:36:26.282 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 45
2019-01-23 09:36:27.385 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 41
2019-01-23 09:36:28.494 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:29.601 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 48
2019-01-23 09:36:30.704 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 50
2019-01-23 09:36:31.815 22279-22279/com.example.thewell_dev.myapplication D/BeaconInfo: BeaconSize 57

但是,第二次输入该活动,

2019-01-23 09:40:12.279 25574-25574/com.example.thewell_dev.myapplication I/ScanJob: Using immediateScanJobId from manifest: 208352939
2019-01-23 09:40:12.279 25574-25574/com.example.thewell_dev.myapplication I/ScanJob: Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@1ceaa9f
2019-01-23 09:40:12.279 25574-25574/com.example.thewell_dev.myapplication I/ScanJob: scanJob version 2.15.2 is starting up on the main process
2019-01-23 09:40:12.283 25574-25574/com.example.thewell_dev.myapplication D/BluetoothAdapter: isLeEnabled(): ON
2019-01-23 09:40:12.286 25574-25574/com.example.thewell_dev.myapplication I/ScanJob: Scan job running for 300000 millis
2019-01-23 09:40:12.286 25574-25632/com.example.thewell_dev.myapplication D/BluetoothAdapter: isLeEnabled(): ON
2019-01-23 09:40:12.287 25574-25574/com.example.thewell_dev.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@d735755 time:18637825
2019-01-23 09:40:12.288 25574-25617/com.example.thewell_dev.myapplication D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=18 mScannerId=0
2019-01-23 09:40:13.018 25574-25636/com.example.thewell_dev.myapplication I/ScanHelper: Non-distinct packets detected in a single scan.  Restarting scans unecessary.

0 个答案:

没有答案