Android的:如何周期性地发送位置服务器 [英] Android: How to periodically send location to a server

查看:197
本文介绍了Android的:如何周期性地发送位置服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个Web服务,它允许用户记录他们的旅程(有点像谷歌的MyTracks)作为一个更大的应用程序的一部分。问题是,它很容易传递数据,包括COORDS等物品,到服务器,当用户启动一个旅行或重圆。作为一个新手,我不知道如何设置发送的位置更新每一个(pre-确定)期间曾后台服务(分3分,最多1小时),直到用户标志的行程结束,或者直到时间的preSET量为止。

I am running a Web service that allows users to record their trips (kind of like Google's MyTracks) as part of a larger app. The thing is that it is easy to pass data, including coords and other items, to the server when a user starts a trip or ends it. Being a newbie, I am not sure how to set up a background service that sends the location updates once every (pre-determined) period (min 3 minutes, max 1 hr) until the user flags the end of the trip, or until a preset amount of time elapses.

一旦行程从手机开始,服务器响应与手机的更新的时间间隔使用轮询周期。这部分的工作,因为我可以显示在手机上的反应,我的服务器注册用户的操作。同样地,行程是在关闭的行程要求关闭服务器端。

Once the trip is started from the phone, the server responds with a polling period for the phone to use as the interval between updates. This part works, in that I can display the response on the phone, and my server registers the user's action. Similarly, the trip is closed server-side upon the close trip request.

然而,当我试着开始从StartTrack活动内的定期跟踪方法,使用requestLocationUpdates(字符串提供商,长minTime,浮minDistance依旧,LocationListener的监听器),其中minTime是来自服务器的轮询周期,它只是没有工作,而我没有得到任何错误。因此,这意味着我无能,在这一点上,从来没有使用的Andr​​oid了。

However, when I tried starting a periodic tracking method from inside the StartTrack Activity, using requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) where minTime is the poll period from the server, it just did not work, and I'm not getting any errors. So it means I'm clueless at this point, never having used Android before.

我看过很多帖子在这里使用的后台服务与处理程序,待处理的意图,和其他的东西做类似的东西,但我真的不知道该怎么做。我想使用者做其他的东西在手机上,而更新回事,所以如果你们可以点我一个教程,说明如何实际编写后台服务(也许这些运行作为单独的课程?)或其他方式这样做,那将是巨大的。

I have seen many posts here on using background services with handlers, pending intents, and other things to do similar stuff, but I really don't understand how to do it. I would like the user to do other stuff on the phone while the updates are going on, so if you guys could point me to a tutorial that shows how to actually write background services (maybe these run as separate classes?) or other ways of doing this, that would be great.

谢谢!

推荐答案

您需要创建一个单独的类,它是服务类的子类。

You need to create a separate class that is a subclass of the Service class.

服务文档

您主要的应用程序应该可以调用 startService stopService 启动后台进程。也Theres在上下文类中的一些其他有用的呼叫管理服务:

Your primary application should can call startService and stopService to start up the background process. Theres also some other useful calls in the context class to manage the service:

<一个href="http://developer.android.com/reference/android/content/Context.html#startService%28android.content.Intent%29">Context文档

这篇关于Android的:如何周期性地发送位置服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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