I was looking through the source code for android 22 to change my code to the new BLE scanning and came across the ScanRecord class. When I opened the source code for ScanRecord (sources/android-22/android/bluetooth/le/ScanRecord.java) I saw that there is a function parseFromBytes:
/**
* Parse scan record bytes to {@link ScanRecord}.
* <p>
* The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18.
* <p>
* All numerical multi-byte entities and values shall use little-endian <strong>byte</strong>
* order.
*
* @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response.
* @hide
*/
public static ScanRecord parseFromBytes(byte[] scanRecord)
But if I try and use it in my code, it cannot find the function. Also if I check the API here, the function is not mentioned at all.
I am using Android Studio 1.3.1 with compileSdkVersion 22, minSdkVersion 18, targetSdkVersion 22 and buildToolsVersion 22.0.1
What am I missing? Why can't I use the function although it is part of the android source code?
Thanks for clarification.
ScanRecord class was added in API level 21. You can get an instance of it from ScanResult Code:
ScanCallback leScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
ScanRecord record = result.getScanRecord();
}
}
On that object instance the public functions are available.
I had the same problem and wanted to use ScanRecord.parseFromBytes. After lots of googling I noticed it has the tag "@hide" which effectively hides it from the compiler. See What does @hide mean in the Android source code?
I'm in two minds to use reflection, but I want access to the fields in ScanRecord (e.g. TxPower)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With