Android 10 Bluetooth disconnecting background services

224 views Asked by At

We're working on a project that includes connecting a sensor to an android device. The android device will send data to google cloud. We're facing a bit of a problem here, and we would appreciate help.

The problem statement is “The Bluetooth connection state is disconnected whenever the screen is switched off, while we need it to work in the background, and keep receiving data from a sensor and sending data to cloud”. Implemented a background service that initializes the bluetooth connections with all following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
1

There are 1 answers

0
Hafed Gabroun On

It turned out that it also depends on the phone type itself. Some phone companies tries to extend the battery life of certain types of phones, so it was shutting down any background service that was not in use.

A work-around that can be done by creating a loop that sends a message every small period of time to maintain the connection.