-
Notifications
You must be signed in to change notification settings - Fork 837
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
Range beacons when app is terminating #1168
Comments
Based on the description, it sounds like the Xiaomi mi A2 is blocking Bluetooth scans after after app termination. Because Xiaomi Android extensions are proprietary, it's unfortunately secret and undocumented what is going on here. Your best bet is to do a variety of tests to reverse engineer what they do in this case. Here are some things you might try:
Unfortunately, I do not have a Xioami device for experimentation, but I am happy to review any logs you can produce with the info above. |
@davidgyoung Let me explain something. When the device is plugged to the PC to get logs from library all is working fine. After 12 or 13 hours when I 'am entering in a ble region the MonitorNotifier fires the didDetermineState with MonitorNotifier.Iside . After that I wan to do a range to get minor and major value from beacons. Can you tell me can I range beacons when app is terminated ? And if yes how can I do? Monitoring works like a charm when app is backgrounded/terminated |
Sorry, I missed your point 4 where you said you get the monitoring entered event successfully. OK, so it is good that scans are working in the background after termination. You say this happens after 12 or 13 hours. Are you saying the ranging callback is not empty fine if you only wait 30 minutes after app termination before triggering a region entry event? If you do not need to wait 12 hours to reproduce the problem that would make testing much faster! I note that you have
Can you confirm the above? Do you get a didRangeBeacons event ~3500ms after the region entry event? Is this the one that has an empty list of beacons? And how long does it take for the next didRangeBeacons callback arrive? Is it empty as well? It would also be helpful if you could try the official reference application (Java version is here: https://github.com/AltBeacon/android-beacon-library-reference) on your phone, which also uses the JobScheduler by default and do both monitoring and ranging in the background. It uses a default background scan period that is a much longer 30000ms. I would like to know if you run that app under the same conditions if its ranging results are non-empty. You'd have to look at LogCat output to see if that is true. |
1 similar comment
Sorry, I missed your point 4 where you said you get the monitoring entered event successfully. OK, so it is good that scans are working in the background after termination. You say this happens after 12 or 13 hours. Are you saying the ranging callback is not empty fine if you only wait 30 minutes after app termination before triggering a region entry event? If you do not need to wait 12 hours to reproduce the problem that would make testing much faster! I note that you have
Can you confirm the above? Do you get a didRangeBeacons event ~3500ms after the region entry event? Is this the one that has an empty list of beacons? And how long does it take for the next didRangeBeacons callback arrive? Is it empty as well? It would also be helpful if you could try the official reference application (Java version is here: https://github.com/AltBeacon/android-beacon-library-reference) on your phone, which also uses the JobScheduler by default and do both monitoring and ranging in the background. It uses a default background scan period that is a much longer 30000ms. I would like to know if you run that app under the same conditions if its ranging results are non-empty. You'd have to look at LogCat output to see if that is true. |
@davidgyoung thank you for your reply again. As far as I observed, sometimes the didRange method is never called and sometimes is called but result is an empty array, all this happens after a certain period of time. I mean when I install the app recently everything works fine. Tested terminating the app and waiting for 30 minutes 15 minutes 20 minutes and ranging works fine. After a couple of hours I don't know why but I can not range beacons in region. If you see I have some notifications for testing purposes after a couple of a time I see "Ranging started from worker" what is mean startRanging function called successfully and stuck it here. I do not get notifications from inside the didRangeBeaconsInRegion. |
I understand that you want to get ranging detections rapidly after region entry, but that may not be possible in 3.5 seconds. Different OEMs configure the Bluetooth chip to use a "scan window" that is very small in certain background modes that makes rapid detections impossible. I would encourage you to experiment with my suggested changes above -- specifically a much longer library SCAN_PERIOD to see if that does make a difference. Even if it is not what you want, it would be a helpful troubleshooting step. Secondly, one other thing you might consider is leaving ranging turned on all the time. There are no battery consequences to doing this. And if you do so you should get one guaranteed ranging result with a detection after region entry. Thirdly, if the above does not solve the issue, I really need you to reproduce this problem with the reference app and attach logs with beaconModule.setDebug(true); showing the empty range result right after a region entry. Please understand that this forum is for reporting and resolving problems with the library, not with third-party apps, so troubleshooting a third party app is out of scope. Please let me know if you can provide logs reproducing the problem with the reference app and I am happy to assist further. |
@davidgyoung there are some logs. When I 'am exited and enter a region gives me these logs. startRangin function called but doesn't run. Did not start ranging for beacons in region. didRangeBeaconsInRegion callback never called from library.
|
Expected behavior
Range beacons while app is terminated
Actual behavior
Getting empty beacon list on didRangeBeaconsInRegion callback.
Steps to reproduce this behavior
My own BeaconsManager class
Worker class that range the beacon is
If run this code device shows me sometimes Ranging started notification and Ranging results are 0. What I understand is that sometimes ranging are starting and resulting with empty beacons list and some times doesn't start correctly. I 'am sure UUID and identifier are correct values. Also I check these values a lot of times. In this project monitoring/ranging only iBeacons.
My scenario is :
1- user opens app one time to start monitoring
2- user exits from app(app now is terminated and monitoring started)
3- user enters with it's own device in beacon region
4- monitor notifier detect beacon and call didDetermineState for inside state
--- So far my code works like a charm
5- when state is inside I want to range beacons to get minor and major values (keep in mind app is terminated )
6- start ranging inside a worker which is run on mainThread
7- I 'am getting here inside the didRangeBeaconsInRegion method an empty beacon list or nothing
I have been added all required permissions
ACCESS_BACKGROOUND_LOCATION
FINE_LOCATION
BLUETOOTH
BLUETOOTH_ADMIN
BLUETOOTH_SCAN
I want to range beacons when app is terminated without show a foreground notification to the user because my ranging process will terminated with the first success result of ranging.
I now my phone is in don't kill my app list. I implement to request disable the battery optimizations permissions and user can disable on UI. All my tests done with disabled battery optimizations.
Please help me!
Thank you for your time and helps!
Mobile device model and OS version
Xiaomi mi A2 android one - (API 29)
Android Beacon Library version
2.20
The text was updated successfully, but these errors were encountered: