奥利奥信标检测

时间:2018-06-28 13:30:20

标签: android beacon altbeacon

///我在后台服务中调用StartScan()函数来获取信标信息。但是,当我运行Android 8应用程序时,无法扫描信标。代码正在运行其他版本的Android。

private void StartScan(){

    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    region = new Region("allbeacons", Identifier.parse(UUID), Identifier.parse("0"), Identifier.parse("0"));

    RegionBootstrap regionBootstrap = new RegionBootstrap(this, region);
    Beacon.setHardwareEqualityEnforced(true);

    BeaconManager.setRssiFilterImplClass(ArmaRssiFilter.class);

    beaconManager.setBackgroundScanPeriod(1200);
    beaconManager.setBackgroundBetweenScanPeriod(0);
    beaconManager.setForegroundScanPeriod(1200); 


    try {
        beaconManager.updateScanPeriods();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    beaconManager.bind(this);

}

@Override     public void onBeaconServiceConnect(){

    try {
        beaconManager.startRangingBeaconsInRegion(region);
    } catch (RemoteException e) {
    }
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(final Collection<Beacon> beacons, Region region) {


            beaconlist = new HashMap<Double, String>();

            if (beacons.size() > 0) {

                  In hear ı can got all beacons info using the other versions of android.

               }

}

@Override
public void didEnterRegion(Region region) {
    try {
        beaconManager.startRangingBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }

}

@Override
public void didExitRegion(Region region) {

    beaconlist.clear();
    try {
        beaconManager.stopRangingBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }

}

我使用此Albeacon库版本  编译'org.altbeacon:android-beacon-library:2.13 +'

0 个答案:

没有答案