-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreground Service on Android #643
Comments
I had the same problem for a while and your solution worked well :) The capawesome plugin works like a charm - why did you suggest it's not the right solution ? |
Hi! Do you have a working example that works together with with the community-bluetooth le plugin? The startForegroundService() function parameters from their interface are only with regards to (local) notifications. So I thought this would not work with the whole BLE plugin. Or do you use the moveToForeground() function? BR |
so turns out a foreground service (while it may work) is not the right approach for BLE background scanning a foreground service should not be running at all times, the documentation actually highlights more appropriate alternative, which is using a Pending Intent as a scan result and using a receiver that is assigned to the application that will make the OS launch the receiver even if the app was previously terminated see more here https://developer.android.com/develop/connectivity/bluetooth/ble/background I'll be opening a PR soon that handles the pending intent and receiver |
see #700 |
That's great thanks a lot! Will this then also hold a connection active to the BLE client, which was established when the app was in foreground and went to background? |
Depends what you're trying to do See the docs for further information on how to handle background activities They suggest subscribing to characteristic notifications if you're looking to get information from the device |
Yes thats exactly what I do with the plugin in my app:
And this part should kept running when the app is going to background. I had a look into the docs. I am familiar with Java a bit, but did not develop in native android. Would be awesome if the plugin has an option to put the notifications on a forground service. |
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":
Here it comes out of the background:
The text was updated successfully, but these errors were encountered: