我现在有一个问题,因为我正试图从我的Onyx iBeacon读取tx-Power.我已经阅读了多个建议并在互联网上尝试了这么多代码,但我仍然无法解决这个问题.
我正在使用android棒棒糖,并尝试了来自https://github.com/devunwired/accessory-samples/tree/master/BluetoothGatt的iBeacon教程,
以获取蓝牙应用程序BLUETOOTH_THERM_SERVICE.
我从广告中找到了tx-Power的两个值: 蓝牙LE TX功率读数
0x1804和它的特点0x2A07,所以我改编了包裹UUID来过滤我的ScanResults 0x1804:
public static final ParcelUuid THERM_SERVICE = ParcelUuid.fromString("00001809-0000-1000-8000-00805f9b34fb");
public static final ParcelUuid TX_POWER_SERVICE = ParcelUuid.fromString("00001804-0000-1000-8000-00805F9B34FB");
public static final ParcelUuid ONYX_STANDARD_SERVICE = ParcelUuid.fromString("0000180a-0000-1000-8000-00805f9b34fb");
Run Code Online (Sandbox Code Playgroud)
如教程中所述:
byte[] data = record.getServiceData(TX_POWER_SERVICE);
Run Code Online (Sandbox Code Playgroud)
应该存储一个字节数组,但它总是返回null!唯一存储字节数组的东西,但我认为它存储整个记录是:
byte[] data = record.getServiceData(ONYX_STANDARD_SERVICE);
Run Code Online (Sandbox Code Playgroud)
尝试继续使用我可以获得的数据,ONYX_STANDARD_SERVICE我可以看到scanResult:
onScanResult() - ScanResult{mDevice=78:A5:04:07:AE:96, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, 32, -54, -24, -96, -87, -49, 17, -29, -91, -30, 8, 0, 32, 12, -102, 102, 0, 7, -82, -106, -78]}, …Run Code Online (Sandbox Code Playgroud) bluetooth-lowenergy ibeacon ibeacon-android android-5.0-lollipop