在后台接收位置更新的最佳方法是什么? [英] What is the best way to receive location updates in background?

查看:77
本文介绍了在后台接收位置更新的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个在后台跟踪位置并将数据发送到服务器的应用程序-例如,监视我的家人的位置.
目前,我正在玩 https://github.com/android/location-samples LocationUpdatesBackgroundKotlin 似乎是接收位置更新的最佳方法,但是

I am trying to write an app that tracks location in background and sends data to a server -- to monitor where my family members are, for example.
Currently I am playing with https://github.com/android/location-samples, particularly with LocationUpdatesBackgroundKotlin that seems to be the best way to receive location updates, but

在后台接收到大约8-10个位置更新后,状态栏上的gps图标将消失,而始终不通知应用程序(fusedLocationClient.requestLocationUpdates 接收更新.com/android/location-samples/blob/main/LocationUpdatesBackgroundKotlin/app/src/main/java/com/google/android/gms/location/sample/locationupdatesbackgroundkotlin/data/MyLocationManager.kt"rel =" nofollow noreferrer> MyLocationManager 帮助接收进一步的更新,但是我必须通过肉眼监视状态).

after receiving about 8-10 location updates in background, the gps icon on the status bar dies without anyway notifying the application (here is the android/phone info, but I want the app to be compatible to Android 5.1).
I want to somehow know is receiving location updates alive or not and re-start it if it's dead (restarting receiving updates with fusedLocationClient.requestLocationUpdates on line 105 of MyLocationManager helps receiving further updates, but I have to monitor the status by eye).

有什么出路,还是更可靠的方法?谢谢.
P.S.已经为Android编写了一个星期.

Is there any way out, or a more reliable approach? Thanks.
P.S. Have been writing for android for a week.

推荐答案

对于Android 5 Lollipop来说,最好使用第三方库来接收免费的位置信息(更稳定),即 io.nlopez.'io.nlopez.smartlocation:library:3.3.3'中的smartlocation.SmartLocation ,如

It comes out for Android 5 Lollipop it's better (much more stable) to use third-party library for bacground location receiving, namely io.nlopez.smartlocation.SmartLocation from 'io.nlopez.smartlocation:library:3.3.3', as decribed here, along with a foreground service, as Rudrik Patel mentioned. Works like a charm.

这篇关于在后台接收位置更新的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆