leedh6654
leedh6654

Reputation: 11

Bluetooth scan does not work in background operation on Android10

I am currently developing an app that connects Bluetooth on Android10 and scans for beacons around it.

I created a service called Public class MyService extends Service implements BeaconConsumer To use BeaconManager in MyService, it is declared as follows, protected static BeaconManager beaconManager;

in the onStartCommand part It is set to use as a Foreground Service using beaconManager.enableForegroundServiceScanning.

MyService is started from start Activity, MainActivity, as startService. When the Activity window is open, the scan function works without problems. However, the scanner function does not seem to work in App Standby Mode or all Doze Modes. Click the notification icon again to activate the Activity window, and the scanner functions.

If you enter an area that satisfies certain conditions, you always want to scan the beacon and receive the data regardless of the state of the phone. If possible, how?

Upvotes: 1

Views: 52

Answers (1)

mrcrambo
mrcrambo

Reputation: 504

If you have a Foreground service, your scan should work correctly.

But if you used not the foreground service, but only simple service, your solution will not work, because starting from Android 23, the DOZE mode will clear all the jobs and services you run on the background.

By the way, waking up in DOZE mode is a real problem and sometimes even setAndAllowWhileIdle() or setExactAndAllowWhileIdle() will not help to avoid it.

You can find more info about working on Doze mode with Bluetooth scanning in this article.

Also here is the information about DOZE mode from Google.

Upvotes: 2

Related Questions