This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Background operation of BLE Library with Android 8 - Request for Example

I would like to ask Nordic to create an example of an Android background service that can detect a device advertising.

Android imposes background execution limits which affect scanning for devices. The issue for beacons is described here and a solution implemented in the Android Beacon Library. Of course, the issue affects all devices and not just beacons. I have asked about this in an earlier post and since then done a fairly ugly implementation.

To set the context: I am working on a digital health sensor with a BLE interface. The user operates the sensor which collects data and saves it. It then starts advertising and will transfer the data when the sensor and the smart phone are next in radio range. The phone then transfers the reading to the cloud. The user does not need to have his phone when he operates the medical device, and he does not need to fire up an app manually in order to send the data to the cloud.

I have an experimental Android app that combines Nordic's Android BLE Library and the Android Beacon Library. I have hacked the Android Beacon Library to listen for my custom 128-bit UUID. This works in Android background mode. When the app detects my BLE custom UUID it fires an event and then I switch over to Nordic's BLE Library to connect to my device and transfer data. (This is obviously out of scope for the Andorid Beacon Library).

Clearly my specific use case can can be generalised: it should be possible for any BLE sensor (not just beacons) to send data to a phone that the user sees as "off".

Most of the time this works very well. But (a) my hack of the Android Beacon Library is pretty ugly, and (b) sometimes my app does not hear my device advertising and I must reset the phone. This is probably because of (a). Also, (c) the Android Beacon Library contains much more code than my app requires.

I would much prefer to work with one library and not two. What chance is the that I can get Nordic to work with me on this? The spec is to create an example Android app that listens for a BLE device in background mode, connects to it, transfers data and disconnects. I would work with you on this.

Parents
  • Hi ,

    We already have https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library which may be used for scanning. Its intent was to emulate all the new features on older devices, including scanning with Pending Intent (a way to scan with background executions limits). On pre-Oreo device it starts a background service that scans and triggers the Pending Intent if a device was found. It of course is using a lot of battery, as requires running service, possibly filtering in CPU, etc, but should work for short scanning periods.

    For long lasting beacon scanning I would, actually, recommend either min SDK set to Oreo and using Pending Intents only, or clear option for the user to disable this on older phones, as this really may kill the battery quickly, a specially before Lollipop.

Reply
  • Hi ,

    We already have https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library which may be used for scanning. Its intent was to emulate all the new features on older devices, including scanning with Pending Intent (a way to scan with background executions limits). On pre-Oreo device it starts a background service that scans and triggers the Pending Intent if a device was found. It of course is using a lot of battery, as requires running service, possibly filtering in CPU, etc, but should work for short scanning periods.

    For long lasting beacon scanning I would, actually, recommend either min SDK set to Oreo and using Pending Intents only, or clear option for the user to disable this on older phones, as this really may kill the battery quickly, a specially before Lollipop.

Children
Related