简体   繁体   English

当屏幕关闭时,Android 10 会阻止网络请求和 GPS 呼叫

[英]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.我制作了一个应用程序,它实际上每 15 分钟将用户位置发送到服务器。 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.当屏幕关闭(锁定)时,它会在一段时间内运行良好,后来它无法发送请求并获取 GPS 数据。 So I used wake lock to turn on screen for 30 seconds so that the device comes out of doze mode.所以我使用唤醒锁打开屏幕 30 秒,以便设备退出打盹模式。

This approach works fine in Android 8,9 but in Android 10 it still fails.这种方法在 Android 8,9 中运行良好,但在 Android 10 中仍然失败。 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.我什至也使用了 PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF 唤醒锁,但仍然阻止了 HTTP 调用和 GPS 数据。 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.我看到正在调用服务,但没有触发 GPS 数据。 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.还有一件事是,我使用Handler甚至Timer Task实现了一个Timer来处理位置超时,这样我就可以在超时发生时发送其他数据,这有时会起作用,有时会失败。

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.顺便说一句,当应用程序关闭时,工作管理器在中文 Roms 中不起作用。

我也面临同样的问题,并通过禁用移动设备中的省电选项解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM