opentrace-community / opentrace-android

OpenTrace Android app. Reference implementation of the BlueTrace protocol.
https://bluetrace.io
GNU General Public License v3.0
577 stars 225 forks source link

Tracing is unreliable once the phone is in your pocket #31

Open acooley opened 4 years ago

acooley commented 4 years ago

Ok, so my apologies if this is not correct, I have not yet read all of your code BUT...

Based on my quick look at your manifest and what I saw with setting up background tasks I don't think you will be able to get the Android version of your application to scan consistently. When Android puts the app into Doze mode your alarm manager won't wake up the app to scan. You can fix that and you can scan at any frequency you want using Alarm Manager even when the application has been killed or the handset has been 'Dozed'. Here's the basics:

add.. to your manifest.

Don't use Alarm manager to schedule a repeating task. Instead, use it to schedule one task at a time with a delay, BUT in the task, schedule the next task. Also in the broadcast receiver you'll need to take the wake lock. I'm going to take a more careful look at your code later today. Please let me know if you would like help fixing this; I've already implemented it this way in our social distance app and it will work here too.

--aaron

puneetkumar1011 commented 4 years ago

Hi,

I am using this code base for my demo app but as soon as the Screen is locked after some time BLE scan stops working there is no advertising and scanning of nearby devices.

In case if I am using the BLE scan and advertising continuously then it works properly. Most of Samsung devices it gives the problem. I have tried by adding Scan filters and whitelist my app but nothing works when the screen is lock/OFF.

Thank you Puneet

NKGodhan commented 4 years ago

Hello,

Want to increase the counter here on the board.

I am building an app to trace data of my surrounding devices (using my app). I am following the same code base, but facing the same issue regarding the BLE devices scan and advertisement when a device goes in the sleep mode OR got locked using the power button.

I checked the same scenario in multiple devices but the result is same, it is unable to scan device advertising data at all. The devices I am testing with are mostly premium devices like Samsung, OnePlus, Motorola etc. I tried most of the methods (as they exists on the web) to resolve the issue, but nothing was good enough.

I am not sure what causing such behavior but please provide a proper solution to fix it if it exists.

Thanks, Nikhil Godhan

xonack commented 3 years ago

bumping the thread to see if there have been any developments.

@acooley Sounds like a great fix!! Is the alarm manager functionality you are describing all in the manifest? or are other files involved as well?

cheers, honack