android-ble-made-easy icon indicating copy to clipboard operation
android-ble-made-easy copied to clipboard

BLE instance in service

Open pawelkaczmarek12 opened this issue 1 year ago • 4 comments

I wanted to use the library in Foreground Service, but at the moment it's not possible. Could you please add a context-only constructor?

pawelkaczmarek12 avatar Jul 26 '23 12:07 pawelkaczmarek12

Hello, Thank you for your issue It is theoretically possible, although I have never tested this on a Service, so it would need testing.

Would you be so kind to offer help to test the library given that I expose a new constructor for you?

LeandroSQ avatar Jul 27 '23 22:07 LeandroSQ

I'd be happy to play around with this - I have a need for BLE in a Foreground Service in a small project I'm working on and I'd love to use this library to make it happen!

lemonjesus avatar Oct 18 '23 00:10 lemonjesus

Thank you for volunteering! I will put out a prototype with this as soon as I get time to it, so we can get this into a new version.

LeandroSQ avatar Oct 24 '23 20:10 LeandroSQ

Just updating this with my findings.

  1. We need special permission to handle connected devices on a foreground service
  2. Couldn't find a way to handle the jetpack contracts on the services, so it may be possible that using helpers like hardware availability, permission checking and so on wouldn't work
  3. It may be only possible to start the BLE instance on an Activity, Fragment or Jetpack compose activity, connect to a device and then pass the connection instance to the service.

LeandroSQ avatar Oct 25 '23 22:10 LeandroSQ