在BLE制造商数据中,当从字节转换到字符串时,我得到的数据如下:
联合JLG
,S 7452396,�90234380,100084,������������������。
甚至从字节转换为十六进制,然后十六进制转换为字符串打印,就像这样。
十六进制格式:
02010608084A4C4720424C45020A0A0FFF530704373435323339360000000015FF5307504839303233343338302C3130303038342C000000000000000000.
在ios中,像这样的数据打印
1.原始数据(Ascii):
53070355 52323031 39313130 33315048 39303233 343338302c313030 3038342c
2.字符串值:
SUR201911031PH90234380,100084
因此,在Android中,如何打印原始数据和字符串值(如iOS )?
我得到这样的扫描结果
ScanResult{device=D6:23:72:02:69:72,scanRecord=ScanRecord,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,advertisingSid=255,txPower=127 }
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*/
}
};发布于 2019-11-22 09:48:40
以下字节位于Android和iOS上接收的原始数据中:
39303233343338302C31303038342C
在此之前,您的联合JLG外围设备在安卓和iOS之间编码不同的制造商数据。
据推测,iOS数据包括外围设备的私有BLE地址,因为使用iOS,不可能通过使用CoreBluetooth的广告包获取广告BLE外围设备的私有地址。
如果您的应用程序需要唯一地标识未知的BLE外围设备,则此标识信息必须由外围设备提供,只要这些信息适合广告包。
https://stackoverflow.com/questions/58990872
复制相似问题