如何让应用程序持续运行GPS? [英] How to keep an app running continually with GPS on?

查看:144
本文介绍了如何让应用程序持续运行GPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要每隔几秒记录用户的位置,就是它的全部时间。



On并不意味着在前台,或者即使是Android的屏幕上。



建议完成它的方法是什么?



我听说过背景和前景服务,并且看到了有关乔布斯的一些信息。我也看到这是可能的一个WakeLock。



我不知道什么是最好的选择方法。


解决方案

您应该使用Service,您可以选择该服务即使在您的应用程序关闭后仍然会继续运行。



如果设备资源不足,它可能会关闭您的服务。
您可以使用FOREGROUND服务,如果您想最大限度地减少机会将关闭您的服务的机会。服务内部的
使用LocationManager / FusedLocation来每X次获取一个位置。
您可以使用LocationListener进行设置,因此每次设置onLocationChanged时,您都可以上传到Firebase。

让您的应用程序知道



服务


I have an application that is required to log the user's location every couple of seconds, the entire time it is on.

On does not mean in the foreground,or that even the Android's screen is on.

What is the suggested way to accomplish it?

I've heard of background and foreground services, and also saw something about Jobs. I also saw this was possible with a WakeLock.

I am not sure what is the best method of choice.

The need to conserve Battery life is of course an issue.

解决方案

You should use Service, you can choose that the service wil keep running even after your app was closed.

YET if the device is low on resources it might close your service. you can use FOREGROUND service if you want to minimize the chance android will close your service. inside the service use LocationManager / FusedLocation to get the location every X time. you set it up with LocationListener so everytime it set onLocationChanged you upload to firebase.

Useful links:

Make your app loaction aware

Services

这篇关于如何让应用程序持续运行GPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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