运行的服务来获得位置信息 [英] Running a service to get location details

查看:102
本文介绍了运行的服务来获得位置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我需要创建一个机器人服务,定期获得移动用户的当前位置(经度和纬度)。服务应该得到用户的位置,每隔5分钟..我怎样才能做到这一点在Android的服务,将在后台运行。这是正确的做法?

In my app, i need to create an android service to periodically get mobile user's current location(latitude and longitude). The service should get user's location in every 5 minutes.. How can i do this in android service that would run in background. And is this the right approach?

推荐答案

您可以写一个私有/内部类(您的服务范围内),实现LocationListener的,并在服务的ONSTART meethod可以requestLocationUpdates将被倾听你的听众

You can write a private/internal class(within your service) that implements locationListener and in the onStart meethod of your service you can requestLocationUpdates which will be listened by your listener

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
MyLocationListener listener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, listener);

这篇关于运行的服务来获得位置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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