尝试将BeaconParser添加到AltBeacon lib时出现异常 [英] Exception when trying to add a BeaconParser to AltBeacon lib

查看:307
本文介绍了尝试将BeaconParser添加到AltBeacon lib时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从AltBeacon修改参考应用检测iBeacons。

I have been trying to modify the reference app from AltBeacon in order to detect iBeacons.

在RangingActivity中,我更换了

In RangingActivity, I replaced

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);
    beaconManager.bind(this);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);
    BeaconParser bp = new BeaconParser();
    bp.setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24");
    List<BeaconParser> lbp = beaconManager.getBeaconParsers();
    lbp.add(bp);

    beaconManager.bind(this);
}

为了应用修改来检测我发现的iBeacon 这里

In order to apply the modifications to detect an iBeacon which I found here.

但是这会抛出,因为 lbp 是一个java.util.Collections $ UnmodifiableRandomAccessList。我是Java的新手,但我想这是一个我无法添加项目的列表,并且在第二个链接中的解决方案之间的库中必须更改一些内容。

However this throws as lbp is a java.util.Collections$UnmodifiableRandomAccessList. I am new to Java but I guess this is a list to which I cannot add items and something must have changed in the library between the solution in the second link and now.

有人知道添加新的 BeaconParser 的正确方法是什么,或者我在这里做错了什么?

Do anybody know what would be the correct way to add a new BeaconParser or what I am doing wrong here ?

推荐答案

我已经在GitHub上回答了你的问题,但我觉得我应该在这里回答,以帮助其他遇到这个问题的人。

I already answered your question on GitHub but I felt like I should answer in here as well to help other people who faces this problem.

我检查了源代码(v2.1.3),很可能你是在绑定beacon服务后添加新的解析器(禁止未来的自定义布局添加)。

I have checked the source code (v2.1.3), most probably you are adding new parser after binding beacon service (which forbids future custom layout adding).

public List<BeaconParser> getBeaconParsers() {
    if (isAnyConsumerBound()) {
        return Collections.unmodifiableList(beaconParsers);
    }
    return beaconParsers;
}

为了在之后添加任何布局解析器,您需要取消绑定所有服务连接还包括所有 RegionBootsrap 。如果您定义了一个,则需要禁用它,因为它还与 BeaconService 建立连接。

In order to add any layout parser afterwards you need to unbind all service connections which also includes all RegionBootsraps. If you defined one, you need to disable it since it also establishes a connection with BeaconService.

但是,我相信您以后不需要添加任何自定义布局。如果要将布局存储在远程中,则应首先获取它们然后绑定 BeaconManager

However, I believe you don't need to add any custom layout later time. If you are storing your layout in remote, you should first fetch them then bind BeaconManager.

BTW,如果你相信这个能力应该添加到库中,你可以在库的GitHub页面上创建一个请求:
AltBeacon GitHub

BTW, If you believe this ability should be added to library, you can create a request on library's GitHub page: AltBeacon GitHub

这篇关于尝试将BeaconParser添加到AltBeacon lib时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆