[英]Android: How to Get location updates in background
I request location updates using fusedLocationProviderClient.requestLocationUpdates()
in onStartCommand()
. 我在
onStartCommand()
使用fusedLocationProviderClient.requestLocationUpdates()
请求位置更新。 It works fine. 工作正常。 But when I close the app or kill the app,
onLocationResult()
is not called. 但是,当我关闭应用程序或
onLocationResult()
该应用程序时,不会调用onLocationResult()
。
You need to use a ForegroundService. 您需要使用ForegroundService。 Here's the complete code for doing exactly what you want:
这是完成您想要做的完整代码:
https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.