[英]Bluetooth Scanrecord same values are null
I tried to read beacon scanresult, some values came but result.getScanRecord().getServiceUuids()
always null.我试图读取信标扫描结果,一些值来了,但
result.getScanRecord().getServiceUuids()
总是 null。
And also i dont understand that how can i parse " result.getScanRecord().getBytes()
".而且我也不明白如何解析“
result.getScanRecord().getBytes()
”。 i saw many example but it is not understandable or so complex.我看到了很多例子,但它无法理解或如此复杂。 i need minor, major and uuid values.
我需要次要、主要和 uuid 值。
I'am using minSdkVersion 21
.我正在使用
minSdkVersion 21
。
Finally I found something, maybe you need too;最后我找到了一些东西,也许你也需要;
firstly, you need parse to data;首先,您需要解析数据;
private String[] myFormula(byte[] data) {
String[] newData = new String[data.length];
for (int i = 0; i < data.length; i++) {
if (data[i] > 0) {
if (Integer.parseInt(data[i] + "", 16) < 9) {
newData[i] = "0" + Integer.toHexString(data[i]);
} else {
newData[i] = Integer.toHexString(data[i]);
}
} else {
newData[i] = Integer.toHexString(data[i] + 256);
}
}
return newData;
}
after you get other datas;获得其他数据后;
public int getTxPower() {
Number xx = hexToDec(scanRecord[26]);
return xx.intValue();
//return Integer.parseInt(scanRecord[26], 16);
}
public int getMinor() {
String s = "";
if (!scanRecord[24].equals("100")) {
s += scanRecord[24];
}
s += scanRecord[25];
try {
return Integer.parseInt(s, 16);
} catch (NumberFormatException e) {
e.printStackTrace();
return -1;
}
}
public int getMajor() {
String s = "";
if (!scanRecord[22].equals("100")) {
s += scanRecord[22];
}
s += scanRecord[23];
try {
return Integer.parseInt(s, 16);
} catch (NumberFormatException e) {
e.printStackTrace();
return -1;
}
}
public void get allDatas(){
scanRecord = myFormula(result.getScanRecord().getBytes());
MINOR = getMinor();
MAJOR = getMajor();
TXPOWER = getTxPower();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.