Gss Aditya
Gss Aditya

Reputation: 153

Android 10 blocks network requests and GPS calls when screen is off

I made an application which actually sends User Location to server for every 15 min. This uses Alarm Manager (one shot) which triggers the next one. The alarm manager triggers a foreground service which is responsible for Fetching user location and Uploading to my server.

The flow works awesome when the user is interacting with the device. When screen is turned off (Locked) it works good for some amount of time, Later its not able to send requests and get GPS data. So I used wake lock to turn on screen for 30 seconds so that the device comes out of doze mode.

This approach works fine in Android 8,9 but in Android 10 it still fails. I even used PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF wake lock too but still the HTTP calls and GPS data is being blocked. I implemented a Logger to save every action which stores in files. I see that the service is being invoked, but the GPS Data is not being triggered. One more thing is that I implemented a Timer using Handler and even Timer Task to handle Location timeout so that i can send other data when timeout happens, this works sometimes and fails sometimes.

How can I be able to solve this issue? Is there any workaround.

Note: The reason i used alarm manager is because they actually trigger when device is in doze. Work manager as per my understanding is meant for the jobs that can be postponed. BTW Work Manager was not working in Chinese Roms when app is closed.

Upvotes: 3

Views: 416

Answers (1)

Zeeshan Ashraf
Zeeshan Ashraf

Reputation: 21

I am also facing the same issue and resolved this by disabling the Power saving option in Mobile devices.

Upvotes: 0

Related Questions