在BLE制造商数据中,从字节转换为String时,我正在获取如下数据:
JLG BLE
ÿS7452396��������ÿSPH90234380,100084,������������������。
即使仅从字节转换为十六进制,然后从十六进制转换为字符串,也是如此。
十六进制格式:
02010608084A4C4720424C45020A0A0FFF530704373435323339360000000015FF5307504839309303343348308302C3130303038342C000000000000000000。
在ios Manufacture数据打印中
1.Raw Data(Ascii):
53070355 52323031 39313130 33315048 39303233 34333830 2c313030 3038342c
2.String值:
SUR201911031PH90234380,100084,
因此,在Android中,如何打印原始数据和类似于iOS的字符串值
我正在得到这样的扫描结果
ScanResult {device = D6:23:72:02:69:72,scanRecord = ScanRecord [mAdvertiseFlags = 6,mServiceUuids = null, mManufacturerSpecificData = {1875 = [80,72,57,48,50,51,52,51,56, 48,44,49,48,48,48,56,52,44]},mServiceData = {}, mTxPowerLevel = 10,mDeviceName = JLG BLE],rssi = -59, timestampNanos = 34872779608333,eventType = 27,primaryPhy = 1, secondaryPhy = 0,advertiseSid = 255,txPower = 127, PeriodicalAdvertisingInterval = 0}
private ScanCallback mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
try {
BluetoothDevice btDevice = result.getDevice();
String name = btDevice.getName();
// Log.d("advertisedData",);
if (name != null && name.equalsIgnoreCase(JLGConstants.BLE_NAME)) {
JLGBluetoothManufacturerData bluetoothManufacturerData = new JLGBluetoothManufacturerData();
bluetoothManufacturerData.setBluetoothDevice(result.getDevice());
bluetoothManufacturerData.setRssi(result.getRssi());
Log.e("address",""+result);
if (bluetoothManufactureDataList.isEmpty()) {
String scanHex = "";
SparseArray<byte[]> advertisedData = result.getScanRecord().getManufacturerSpecificData();
ScanRecord advertisedDataBytes = result.getScanRecord();
Log.d("advertisedData hex format",JLGCommonFunctions.bytesToHex(advertisedDataBytes.getBytes()));
Log.d("advertisedData String format",JLGCommonFunctions.bytesToString(advertisedDataBytes.getBytes()));
}
}
} catch (Exception e) {
JLGCommonFunctions.logExceptions(e);
}
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
/*do nothing*/
}
@Override
public void onScanFailed(int errorCode) {
/*do nothing*/
}
};
答案 0 :(得分:0)
以下字节包含在Android和iOS上收到的原始数据中:
39303233343338302C3130303038342C
在此部分之前,您的JLG外设在Android和iOS之间编码不同的制造商数据。
大概iOS数据包含外围设备的专用BLE地址,因为在iOS上,无法使用CoreBluetooth通过广告包获取广告BLE外围设备的专用地址。
如果您的应用有必要唯一地识别未知的BLE外设,则该识别信息必须由外设提供,只要该信息适合广告包即可。