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

Simpler tutorial/example #72

Closed beegee-tokyo closed 5 years ago

beegee-tokyo commented 5 years ago

Sorry to bother, as this is not really an issue.

I am not a super experienced programmer for Java but was able to write an app to communicate with a nRF52832 that has a custom characteristic. I have a working code using BlueroothLeService.java that is used in many examples/tutorials but have some performance issues with it.

I tried to use the nRF Toolbox and nRF Blinky code to get an idea how to use this library but they are very difficult (code scattered over several fragments/activities or using specific BlinkyViewMode).

Is there any simple code example that shows how to connect to a device, connect to the characteristic, enable notifications and receive/send data?

Thanks for any link and help.

philips77 commented 5 years ago

The usage of BLE Library in nRF Blinky is very simple. It's just one class: https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/master/app/src/main/java/no/nordicsemi/android/blinky/profile/BlinkyManager.java The BLE Manager is responsible for managing a single connection. It should expose API that can be used by other classes, for example the one above has 'send(boolean) method. The callbacks from the device (in case of Blinky a callback is called when used clicks a button on the DevKit) are in this package and they are called directly from the Ble Manager linked above.

BLE Manager may be used in a Service, from ViewModel, or directly in the activity if you are not scared of orientation changes and memory leaking, etc. The remaining classes of nRF Blinky are responsible for scanning or UI and are not needed to understand how to use BLE Library.

Billideveloper commented 2 years ago

how to get connection state updates and how to discover service and how to notify , it is needed to use default Gatt call backs