用altbeacon android无法找到任何信标

时间:2018-08-29 06:00:07

标签: android beacon altbeacon

我正在为Android使用altbeacon,但无法检测到我的信标。我也尝试了https://github.com/AltBeacon/android-beacon-library-reference示例代码,但无法检测到信标。这是我的代码:

公共类BeaconApplication扩展了应用程序实现的BootstrapNotifier {

time.Duration

}

公共类SelfBeaconService扩展了Service实现BeaconConsumer {

private Region region;
private RegionBootstrap regionBootstrap;
private BeaconManager beaconManager;

@Override
public void onCreate() {
    super.onCreate();
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.setBackgroundScanPeriod(5000);
    beaconManager.setBackgroundBetweenScanPeriod(10000);
    region = new Region("backgroundRegion",
            Identifier.parse("EBEFD083-70A2-47C8-9837-E7B5634DF524"), null, null);
    regionBootstrap = new RegionBootstrap(this, region);
    Log.i("selfBeacon", "Bootstrap created");
}

@Override
public void didEnterRegion(Region region) {
    Log.i("selfBeacon", "Bootstrap didEnterRegion");
    regionBootstrap.disable();
    Intent intent = new Intent(this, SelfBeaconService.class);
    if (Build.VERSION.SDK_INT >= 26) {
        startForegroundService(intent);
    } else {
        startService(intent);
    }
    Log.i("selfBeacon", "Service start commanded");
}

@Override
public void didExitRegion(Region region) {

}

@Override
public void didDetermineStateForRegion(int i, Region region) {

}

public void resumeScanning () {
    beaconManager.setBackgroundScanPeriod(5000);
    beaconManager.setBackgroundBetweenScanPeriod(10000);
    regionBootstrap = new RegionBootstrap(this, region);
    Log.i("selfBeacon", "scanning resumed");
}

}

1 个答案:

答案 0 :(得分:0)

要检查的几件事:

  1. 确保已添加代码以在运行时动态请求位置权限。有关如何操作,请参见here
  2. 添加以上内容后,请确保已正确获得此许可。去。设置->应用-> {您的应用名称}->查看权限
  3. 确保手机上已启用蓝牙和位置。
  4. 如果您已检查以上所有内容,但仍无法正常工作,请尝试使用BeaconScope之类的现成信标检测器。如果未检测到,则您的电话硬件或信标硬件可能存在问题。