[英]Multiple Beacon Consumer and beacon is not detecting using AltBeacon
[英]Which method in AltBeacon lib converts beacon ID to Hex?
在設置信標Id1之前,我選擇一個比方說0x317a6e65657267
的值。但是,當檢測到信標時,我嘗試使用beacon.getId1
來獲取Id1,相同的ID更改為00000000-0000-0000-0031-7a6e65657267
。 我正在尋找一種可以將檢測到的ID更改為HexString格式的方法。 類似method(00000000-0000-0000-0031-7a6e65657267)
返回0x317a6e65657267
從文檔中,我嘗試了toHexString
和Identifier.parse
方法,但它們沒有幫助。
目前 ,我依靠字符串操作,這可能不是最好的方法。
使用AltBeacon 2.12.4
編輯:這就是我設置信標ID1的方式
//username is a String I get from EditText
//EditText only allows 15 characters a-z, A-Z, 0-9, ".", "-", "_"
//This is how I store the value
byte[] bytes = username.getBytes();
Identifier ALT_BEACON_USER_ID = Identifier.fromBytes(bytes, 0, bytes.length, true);
String ALT_BEACON_ID_1 = ALT_BEACON_USER_ID.toString();
preferences.edit().putString(Constants.ALT_BEACON_ID_1_REF, ALT_BEACON_ID_1).apply();
//Next part is in the Activity where I advertise
String ALT_BEACON_ID_1 = sharedPreferences.getString(ALT_BEACON_ID_1_REF, INVALID);
Beacon beacon = new Beacon.Builder()
.setId1(ALT_BEACON_ID_1)
.setId2("1")
.setId3("2")
.setManufacturer(0x0118)
.setTxPower(-59)
.setDataFields(Arrays.asList(new Long[] {0l}))
.setBluetoothName(username)//username is fetched from sharedpreferences
.build();
//This is how I get the beacon Id1
byte[] bytesBeaconId1 = beacon.getId1().toByteArrayOfSpecifiedEndianness(false);
了解每種信標格式具有每個信標標識符的固有大小。 對於AltBeacon格式,第一個標識符始終為 16個字節,默認情況下以32個十六進制字符的UUID格式表示,並用短划線分隔。
即使您嘗試將較少的字節放入發送器的此標識符中,也將發送完整的16個字節。 如果您不關心所有這些字節並希望發送更少的字節,則由您決定在發送時添加填充字節,在接收時刪除它們。 該庫沒有提供執行此操作的方法。
我建議您只使用問題底部的字節數組,然后:
String username = new String(stripped bytes);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.