NordicSemiconductor / Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
BSD 3-Clause "New" or "Revised" License
2.02k stars 417 forks source link

How to get access to discovered services #91

Closed michal-narajowski closed 5 years ago

michal-narajowski commented 5 years ago

Hi,

I can see that the service discovery starts automatically after the connection, but I can't find a way to access these discovered services. I tried looking through the code in BleManager class and I don't think the library exposes BluetoothGatt object or has an API to access discovered services.

I would appreciate your help.

philips77 commented 5 years ago

Have a look at this method in nRF Blinky: https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/065ab072219f0c9a7fed1e00661effe6d75605eb/app/src/main/java/no/nordicsemi/android/blinky/profile/BlinkyManager.java#L153

philips77 commented 5 years ago

There is also isOptionalServiceSupported(BluetoothGatt) method.

michal-narajowski commented 5 years ago

@philips77 Thanks for your help. I think I can use that.

Is there a way to use this library from a peripheral side? E.g. I start advertising and then after the connection I use the same API as when I'm central.

philips77 commented 5 years ago

You can use it as a peripheral, but will only work for one side of the connection, the client side. When the target device connects to you, and you'll get the server callback, just use the BLE Library with that BluetoothDevice that you got as a parameter. It will discover services in the other side and you'll be able to use it normally. But the server side is missing. There's no option to define gatt server services, advertise or do server operations, like send notifications/indications, wait for write/read, wait for mtu or phy request, etc. That's in fact missing and should be added one day. In nRF Toolbox, in Proximity profile, we do this separately.