bluetooth-lowenergy - Altbeacon 库不适用于 Android 5.0

标签 bluetooth-lowenergy android-5.0-lollipop ibeacon-android altbeacon

昨天我在 Nexus 4 上获得了 Android 5.0 的更新,altbeacon 库停止检测信标。看起来 didEnterRegion 和 didRangeBeaconsInRegion 在监视和测距时甚至都没有被调用。

即使来自 Radius Networks 的 Locate 应用程序现在的行为也有所不同,信标的值一旦被检测到,就不再更新,并且通常看起来好像信标超出了范围。

我注意到的一件事是,现在在 logcat 中出现以下行“BluetoothLeScanner:找不到回调包装器”。我继续找那个类,看到它是在Android L中引入的,但我不知道这是否与它有关。

重要的是,在更新之前,我一直在使用定位应用程序和引用应用程序,没有任何问题。

我不知道这是否是一个普遍的问题,但如果它发生在我身上,我相信它可能发生在其他人身上,所以任何帮助都将不胜感激。

提前致谢!

更新:

在使库工作失败后,我决定尝试使用该库的 Android L 分支。我所做的是将新库插入引用应用程序,但也没有按预期工作。

通过在设备进入新区域时发出通知,Monitor Activity 似乎工作正常。然而,测距事件不报告任何信标,尽管 didRangeBeaconsInRegion 被调用,但总是报告零信标。奇怪的是,当事件暂停(暂时切换到另一个应用程序)时,logcat 显示现在 didRangeBeaconsInRegion 确实被实际信标调用了。

我现在有点卡住了,因为我不知道如何让任何库在 Android L 上工作,所以再次,任何帮助将不胜感激。

最佳答案

我在 5.0+ 上使用最新的 Altbeacon 构建并且没有问题。事实上,我从未在 kitkat 上使用过它,所以我不确定我能帮上什么忙,但这是我的工作代码,它可以听 iBeacons。

实现信标消费者:

public class MainActivity implements BeaconConsumer

初始化信标管理器
        beaconManager = BeaconManager.getInstanceForApplication(this);
        if (beaconManager != null && !beaconManager.isBound(this)) {
        beaconManager.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconManager.bind(this);
    }

onConnect 并启动监听器
            @Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            if (beacons.size() > 0) {
                Beacon firstBeacon = beacons.iterator().next();

            }
        } 
     });
    beaconManager.startRangingBeaconsInRegion(new Region("com.example.app", null, null, null));
}

此代码适用于 3 个设备
  • 连结 4 5.0.1
  • 三星 Galaxy s4 - 股票 5.0.1
  • 三星 Galaxy s4 - CM12 5.1.1
  • 关于bluetooth-lowenergy - Altbeacon 库不适用于 Android 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26999879/

    相关文章:

    android - Altbeacon Android 库 - didRangeBeaconsInRegion

    android - 需要为 Android 6.0 上的蓝牙低功耗扫描启用位置

    android - 你会如何做智能手机BLE室内检测和定位?

    linux - 有没有办法在兼容蓝牙 2.0 的情况下运行 iBeacon。设备?

    ios - 是否可以为 iBeacon 提示设置延迟时间?

    android - API 21 (Lollipop) Android 上的主题对话框

    android - IBeacon Android 中的 "If two apps register ranges with the same id, they clobber eachother"是什么意思

    android - 如何在 Android 中禁用 Lollipop 转场动画

    java - Android Lollipop 设计问题

    ibeacon-android - 在 Cordova 插件中使用 iBeacons,即在 Activity/Service 之外