로그에 대해서는 확실하지 않지만 데이터를 가져 오는 방법은 다음과 같습니다.
onLeScan() 콜백에는 로그에 인쇄되는 모든 정보가 있습니다. 장치 정보를 얻으려면 콜백 (예 : device.getAddress())에서 장치 개체를 사용할 수 있습니다. 스캔 레코드는 콜백의 scanRecord 바이트 배열에 있습니다. 정보를 얻으려면 배열을 구문 분석해야합니다. 아래 코드를 사용하여 스캔 정보를 구문 분석했습니다.
public WeakHashMap<Integer, String> ParseRecord(byte[] scanRecord) {
WeakHashMap<Integer, String> ret = new WeakHashMap<>();
int index = 0;
while (index < scanRecord.length) {
int length = scanRecord[index++];
//Zero value indicates that we are done with the record now
if (length == 0) break;
int type = scanRecord[index];
//if the type is zero, then we are pass the significant section of the data,
// and we are thud done
if (type == 0) break;
byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
if (data != null && data.length > 0) {
StringBuilder hex = new StringBuilder(data.length * 2);
// the data appears to be there backwards
for (int bb = data.length - 1; bb >= 0; bb--) {
hex.append(String.format("%02X", data[bb]));
}
ret.put(type, hex.toString());
}
index += length;
}
return ret;
}
블렌드 광고에 대해 알아 보려면 아래 링크를 참조하십시오. 이 도움이
BLE obtain uuid encoded in advertising packet
희망.
도움 주셔서 감사합니다. scanRecord 바이트 배열을 처리하는 것이 좋습니다. – stev90098289dev
도움을 주셔서 감사합니다. scanRecord 바이트 배열을 처리하는 것이 좋습니다. 그러나 LogCat에서 BluetoothLeScanner 클래스 또는 onScanResult() 메소드가 이미 scanRecord 바이트 배열로 처리하고 읽을 수있는 MANUFACTURING DATA 및 기타 데이터 정보를 비롯한 잘 레이블 된 문자열을 출력하는 것으로 보입니다. LogCat에서이 문자열을 사용할 수 있다면 편리 할 것입니다. – stev90098289dev