Android Question Background task with BLEManager2 and Beacon

mauriziobevilacqua

New Member
Licensed User
Longtime User
We have an app that scans for BlueTooth devices, searching for devices using iBeacon Protocol, but we have a problem with BleManager2:
when phone go in DOZE mode (Screen in black or pushing power button) scan of devices stops and restarts when phone reactivates.
When the app is active or in background, BLE scan runs correctly, we have problem only in DOZE mode.

In this state the service continues running but no BLE Beacon device is founded and the sub 'Manager_DeviceFound', in which we catch data from BT Beacon, is never invoked.
It seems that BLE Scan stops or become incapable to retrieve BT Beacon devices when in DOZE mode.

We have tried “MyLocation” example by Erel, inserting in "Tracker" service module the BleManager2 (public object in Process_Globals)
and the calling "scan2" function in sub "ScanTrack" after checking permission for ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION,
but we have the same problem: in doze mode gps is giving data, BLE scan stops.


We have added to manifest:
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
android:targetSdkVersion="29"


We have B4A 9.50, and we use a Samsung Galaxy A20e with android 10 for testing (Adaptive Battery disabled) .

On an old Tablet (Samsung SM-T561 with android 4.4.4) BT is functioning correctly even in DOZE mode.

Are there some permissions or settings that we have to set for android 10? Does BleManager2 need to be updated? Something we are missing in B4A?
Tips?

Thanks in advance
 

maurizio bevilacqua

New Member
Licensed User
Hi Erel,
we switch to B4A 9.80, add our app in the whitelist but without sucess.
The main answer is: is it possible to realize an app that continues to work while in background and when Android enters doze mode?
 
Upvote 0

maurizio bevilacqua

New Member
Licensed User
Location tracking utilizes GPS while in our app we are trying to use a 'continous' bluetooth connection.
On Android 6 or earlier version it runs fluently; on Android 10 entering doze mode pauses the app.
We are assuming that it depends on energy policy introduced with the latest versions of Android that interfere with the app (even if it is whitelisted).
What do you think about it? And in case, does anyboby have an idea to troubleshoot?
Thanks for answering
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Some ideas:

1) If this app is a commercial app and battery drain is not an issue because the device will be always plugged in, then maybe you can do a full lock using lock.KeepAlive along with configuring the device's setting to never shut off the display.
2) Otherwise, you may not be able to get your app to run 24/7, but you can try to run it at least every minute using the StartServiceAt function (this should wake the device out of doze mode when the specified time arrives).
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User

Did you solve your issue ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…