Java 信标和涡流检测问题
问题在于检测IBeacon和Eddystone帧,当我有Eddystone时,我必须使用特定的函数,IBeacon也是如此。 我在Android Studio中使用Java,因此向我提供IBeacon结果的函数是GetManufactureSpecificData(),而Eddystone的函数是getServiceData()。 问题是为什么会有不同的功能产生结果?如何检查接收到的帧是Eddystone还是IBeacon 代码片段Java 信标和涡流检测问题,java,android-studio,beacon,Java,Android Studio,Beacon,问题在于检测IBeacon和Eddystone帧,当我有Eddystone时,我必须使用特定的函数,IBeacon也是如此。 我在Android Studio中使用Java,因此向我提供IBeacon结果的函数是GetManufactureSpecificData(),而Eddystone的函数是getServiceData()。 问题是为什么会有不同的功能产生结果?如何检查接收到的帧是Eddystone还是IBeacon 代码片段 public void onBatchScanResu
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
beaconManager.clean();
Log.i(TAG, "On batch called, size of result is : " + results.size());
for (int index = 0; index < results.size(); ++index) {
try {
ScanRecord mScanRecord = results.get(index).getScanRecord();
Map<ParcelUuid, byte[]> myMap = mScanRecord.getServiceData();
int mRsi = results.get(index).getRssi();
String url = "";
byte[] txPower = new byte[1];
byte[] nameSpaceId = new byte[10];
byte[] instanceId = new byte[6];
float distance;
for (Map.Entry<ParcelUuid, byte[]> eddystoneFrame : myMap.entrySet()) {
// for eddystone URL
if (eddystoneFrame.getValue()[0] == 16) {
url += urlSchemePrefix[eddystoneFrame.getValue()[2]];
for (int i = 3; i < eddystoneFrame.getValue().length - 1; i++) {
url += (char) eddystoneFrame.getValue()[i];
}
url += topLevelDomain[eddystoneFrame.getValue()[eddystoneFrame.getValue().length - 1]];
txPower[0] = eddystoneFrame.getValue()[1];
distance = (float) Utils.calculateDistance((int) txPower[0], (double) mRsi);
try {
beaconManager.addEddyBeacon(Utils.bytesToHex(nameSpaceId), Utils.bytesToHex(instanceId), distance);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
else if (eddystoneFrame.getValue()[0] == 0) {
// For Eddystone UID
System.arraycopy(eddystoneFrame.getValue(), 2, nameSpaceId, 0, nameSpaceId.length);
System.arraycopy(eddystoneFrame.getValue(), 12, instanceId, 0, instanceId.length);
System.arraycopy(eddystoneFrame.getValue(), 1, txPower, 0, txPower.length);
distance = (float) Utils.calculateDistance((int) txPower[0], (double) mRsi);
/** beaconList.add(new String[]{"Name Space ID : " + Utils.bytesToHex(nameSpaceId)+ "\n" + "Instance ID :" + Utils.bytesToHex(instanceId),
String.format("%.2f", distance),
"eddystoneuid"});**/
try {
beaconManager.addEddyBeacon(Utils.bytesToHex(nameSpaceId), Utils.bytesToHex(instanceId), distance);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
Log.i(TAG, "The size of the frame is: " + eddystoneFrame.getValue().length);
}
} catch (Exception e) {
Log.e("Error123456789", e.toString());
break;
}
}
public void onBatchScanResults(列出结果){
super.onBatchScanResults(结果);
beaconManager.clean();
Log.i(标记,“在调用批处理时,结果的大小为:“+results.size()”);
对于(int index=0;index
蓝牙SIG标准机构定义了两种蓝牙LE广告:
抱歉,我不明白这个问题。如何比较类型?
instanceof
getScanRecord提供的结果,如何检查帧类型?否则是IBeacon帧还是Eddystone帧?结果是一个列表。列表不是帧。是的,我知道,但结果可以通过使用所述函数之一为我提供帧负载。为了让问题更清楚,onBatchResult中接收的results参数是一个result对象列表,每个对象都有关于帧的信息,因此使用这些函数可以在不知道检测到哪种信标的情况下提供有效负载。