4
votes

I'm a newbie of BLE programming on android.

In my first apps using BLE on android, I have a big problem.

I got a ScanRecord from Apple Bluetooth Headset using this function.

@Override public void onScanResult(int callbackType, ScanResult result)

and I got a manufacturer data using Apple corp, ID(0x4C). after that, I don't know how to decode a manufacturer data.

I want to auxiliary bluetooth headset information such as battery info, direction info etc. but I don't know how to decode the manufacturer data.

I also searched Apple development document(https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf) But that guide document didn't help me.

Anyway, anyone who tell me how to resolve this problem?!!?! Thank you to read my question.

1
Could you give more information on the bluetooth headset, like a link to them on the apple store? And are you sure they're using BLE instead of regular bluetooth?zafrani
@zafrani Thank you for reply on my article. I got the message from apple bluetooth slave machine in my app and this is my decoded datakunulee
ScanResult{ device=52:BD:E0:86:4F:37, scanRecord=ScanRecord [mAdvertiseFlags=-1, mServiceUuids=null, mManufacturerSpecificData= {76=[ 7, 25, 1, 2, 32, 83, -86, 20, 1, 0, 0, -121, -90, -59, 127, -95, -48, 88, 73, 40, -28, 112, -12, 47, 123, -30, 113]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], rssi=-44, timestampNanos=153422579543736, eventType=16, primaryPhy=1, secondaryPhy=0, advertisingSid=255, txPower=127, periodicAdvertisingInterval=0}. This message said this bluetooth headset is BLE device.kunulee

1 Answers

1
votes

Ok so from your comment it looks like you scanned the device over BLE and want to use one of the services it offers to get information like battery info.

  1. The first thing you will need to do establish a connection to the BLE device. The scanresult you pasted has a method getDevice you'll need to call

  2. After you get the device you can call its connectGatt method. This will attempt to connect your phone and BLE device.

  3. The connectGatt method from step 2 requires a callback. When the connection is successful or unsuccessful the callback will fire onConnectionStateChanged. If successful it will have the success status. This method will also give you a gatt device we will use in step 4.

  4. If step 3 was successful we can assume your phone is connected. The next thing we want to do is discover services. You do this by using the gatt devices discoverServices method.

  5. When the services are discovered your callback will fire onServicesDiscovered. At this point you can now use services. Depending on the API of the headphones they'll want you to read, or subscribe to a services characteristic and descriptor. Since I don't know the API I can't help you further. But you'll end up needing to use one or more of the following:

And the value will return to your callback on. Keep in mind you must wait for the callback for each request before write/reading/subscribing to another characteristic or descriptor.