我已将https://github.com/AltBeacon/android-beacon-library的2.0-beta6版本集成到我的Android应用程序中。打开调试后,我看到我的Roximity iBeacons被看到,但由于字节意外而被信标解析器拒绝。例外设置(示例)使用Android Beacon Library的iBeacon解析器布局
在参考应用有以下注意事项:
// By default the AndroidBeaconLibrary will only find AltBeacons. If you wish to make it
// find a different type of beacon, you must specify the byte layout for that beacon's
// advertisement with a line like below. The example shows how to find a beacon with the
// same byte layout as AltBeacon but with a beaconTypeCode of 0xaabb
//
// beaconManager.getBeaconParsers().add(new BeaconParser().
// setBeaconLayout("m:2-3=aabb,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
//
// In order to find out the proper BeaconLayout definition for other kinds of beacons, do
// a Google search for "setBeaconLayout" (including the quotes in your search.)
我创造了我认为是正确的格式的字符串(在执法机关对我的测试应用足够好),并试图以非常以下设置防守代码:
List<BeaconParser> beaconParsers = beaconManager.getBeaconParsers();
if (beaconParsers != null) {
// We can add a new parser
String roximityBeaconParser = this.getRoximityBeaconParserString();
BeaconParser beaconParser = new BeaconParser();
Log.e("iBeacon", "About to set BeaconLayout with " + roximityBeaconParser);
try {
beaconParser.setBeaconLayout(roximityBeaconParser);
beaconParsers.add(beaconParser);
} catch (BeaconLayoutException e) {
e.printStackTrace();
}
}
我自己的字符串导致了错误,所以我改变了我的函数来获取解析器串简单的例子,从注复制:
private String getRoximityBeaconParserString() {
String result = "m:2-3:beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25";
return result;
}
的代码,尝试设置解析器串线导致BeaconLayoutException:
beaconParser.setBeaconLayout(roximityBeaconParser);
的异常堆栈跟踪没有有用的信息,说什么是错的字符串。
我在做什么错?
感谢您排除故障,并为此感到遗憾。在GitHub中打开一个针对开源库的问题? – davidgyoung 2014-09-26 17:47:43
@davidgyoung当然 - 我会尽力在这个周末完成。如果我不那么唠叨我,万一我忘了。在缺少术语时出现的异常消息(复制/粘贴错误)中也存在错误 - 有两个“您需要一个术语”消息。我会把所有这些放在我的缺陷报告中。伟大的图书馆,目前专注于为什么我现在没有收到通知解析器识别我的iBeacon。知道源代码在github上的位置使得这一点变得如此简单。 – Colin 2014-09-26 17:54:39