简体   繁体   English

无需在Android中运行服务即可在后台获取位置更新

[英]Get Location updates in background without running Service in Android

I want to fetch the current Location of the user in background. 我想在后台获取用户的当前Location I know how it can be done using Service in Android. 我知道如何在Android中使用Service来完成。 But I would like to know is there any possibilities to get user Location without running service. 但是我想知道是否有可能在不运行服务的情况下获得用户位置。 Like using BroadcastReceiver or anything? 喜欢使用BroadcastReceiver还是其他? I'm just trying to avoid running Service to fetch Location . 我只是想避免运行Service来获取Location

For Example I referred this link . 例如,我引用了此链接 But I couldn't follow how to do like this. 但是我不知道该怎么做。

Any help will be appreciated. 任何帮助将不胜感激。 Correct me in case I'm asking anything wrong. 纠正我,以防万一我有任何问题。

EDIT: Oh, I think in the above link he is using Service to get the Location. 编辑:哦,我想他在上面的链接中使用服务来获取位置。 So I think it's not possible to get location in background without running a Service. 因此,我认为如果不运行服务就无法在后台获取位置。 Still suggestions are welcomed. 仍然欢迎提出建议。

You Should Implement a BroadcastReceiver that receives alarm every 2 hours. 您应该实现一个BroadcastReceiver,每2小时接收一次警报。 That alarm is Set by Your Activity. 该警报由您的活动设置。

When the alarm is triggered by your System, Broadcast Receiver receives it, Executes Your Process in BroadCastReceiver. 当警报由您的系统触发时,广播接收器会收到警报,并在BroadCastReceiver中执行您的过程。

This is what i can think of. 这就是我能想到的。

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

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