capacitor-community / capacitor-community/bluetooth-le

Foreground Service on Android

Open
#643 11 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
361
Forks
121
Avg merge
10d 45m
Merged PRs (30d)
2

Description

**Is your feature request related to a problem? Please describe.**
On Android the communication is interrupted after a few minutes Minutes when the app (Ionic/React) is in background. This comes from the Android OS power saving. On iOS this is not the case when BLE service has the permission to run in background. On Android the BLE service needs to be moved to a foreground service, otherwise it gets interrupted. For applications which need to stay connected in background to acquire sensor data for example or want to do a reconnect if the ble device gets lost, this is not currently not possible.
When the app comes from background, it seems that all the messages are spit out at one time, overloading nearly my backend. So it seems, that somehow it is running in BG, but the callback is not thrown.

**Describe the solution you'd like**
It would be great, if there would be a function to put at least the callback of the startNotifications() service into foreground, that we can still send and receive ble packets to the client. This would be also great for the scanning function as well as connect and disconnect if the connection of the ddevice was lost and to be able to do a reconnect in background.

**Describe alternatives you've considered**
I was looking into the https://github.com/capawesome-team/capacitor-plugins/tree/main/packages/android-foreground-service
plugin, but it seems it is not suited to do the task.

**Additional context**
Here it went into "standby mode":
Bildschirmfoto 2024-04-09 um 19 41 12

Here it comes out of the background:
Bildschirmfoto 2024-04-09 um 19 42 31

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Start by reviewing the repository's Android BLE implementation and the referenced capacitor-plugins foreground-service plugin, then determine how background notifications, scanning, connection recovery, and reconnect callbacks are handled. Done means the requested BLE operations remain usable in Android background mode without delayed callback bursts.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, react, typescript
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.