我已將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