Android method missing: ScanRecord.parseFromBytes

I searched the source code for android 22 to change my code to a new BLE scan and came across a ScanRecord class. When I opened the source code for ScanRecord (sources / android-22 / android / bluetooth / le / ScanRecord.java), I saw that the parseFromBytes function exists:

/** * 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 to use it in my code, he will not be able to find this 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 this function, although it is part of the Android source code?

Thanks for clarifying.

+4
source share
2 answers

The ScanRecord class has been added to the Level 21 API. 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(); } } 

Public functions are available in this instance of the object.

+3
source

I had the same problem and wanted to use ScanRecord.parseFromBytes. After many searches, I noticed that it has a "@hide" tag that effectively hides it from the compiler. See What does @hide mean in Android source code?

I'm in two minds to use reflection, but I want to access the fields in ScanRecord (e.g. TxPower)

+1
source

All Articles