跟踪用户的短信,并在后台地理位置 - 是我的主意工作? [英] Tracking user's sms and geo position in the background - is my idea working?

查看:159
本文介绍了跟踪用户的短信,并在后台地理位置 - 是我的主意工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的新鲜与Android。我面对一些雄心勃勃的大学的项目,所以我希望你能告诉我,如果我的想法对下列应用程序的执行是正确的,有效的:

I'm fresh with Android. I face some ambitious university project, so I hope you'll tell me if my idea about following app's implementation is correct and efficient:

业务场景:

  • 在WebService的消耗有关用户的SMS(sendt /接收)和GPS信息/网络提供位置
  • GPS /网络提供位置的应该是sendt到web服务每1分钟(如果它的价值变化)
  • 在手机短信更新,应立即sendt到的WebService

我实施的想法......

我要使用AlarmManager prepare意图匹配的BroadcastReceiver(并用1分钟的时间间隔安排它)。然后我会开始 WakefullIntentService 中的onReceive()方法。这会养活我的WebService的背景。这将工作在后台发送数据通过HTTP。

I'm going to use AlarmManager prepare Intent matching BroadcastReceiver (and schedule it with 1 minute interval). Then I'll start WakefullIntentService in onReceive() method. This will feed my WebService in the background. That would work for sending data over HTTP in the background.

...和疑惑:

如何更新GPS /背景网络提供位置数据?我应该开始一些额外的服务,并在其中使用LocationListener的?不会有意识使用AlarmManager然后 - 我可以从该位置监控服务养活我的WebService

How about updating GPS/"network provided" position data in the background? Should I start some additional service and use LocationListener within it? There would be no sense for using AlarmManager then - I could feed my WebService from this location-monitoring service.

不过,正如我在这里读到:钻石永远是。服务不。这不是一个很好的实践永无止境的服务,以发挥。据我了解,将无法正常工作时,我的手机是睡着了。

But as I read here: Diamonds Are Forever. Services Are Not. it's not a good practise to play with never-ending services. As I understand it would not work correctly when my phone is sleeping.

推荐答案

不要使用报警管理。这是不必要的,你想要做什么。

Do not use the alarm manager. It is unnecessary for what you want to do.

使用实现LocationListener的后台服务。你可以指定你想要多久检查的位置更新,甚至多少距离必须以认为这是一个新的位置发生改变。这是在requestLocationUpdates方法进行。

Use a background service that implements LocationListener. You can specify how often you want to check for location updates and even how much distance must change in order to consider it a new location. This is done in the requestLocationUpdates method.

下面是一些code,让你开始:

Here is some code to get you started:

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 1, this);

此将试图获得一个新的位置,每60秒,仅在距离已经由1米改变。也就是说,如果上述条件得到满足的位置监听器才会触发。

This will try to get a new location every 60 seconds and only if the distance has changed by 1 meter. That is the location listener will only fire if the conditions above are met.

希望这有助于。

这篇关于跟踪用户的短信,并在后台地理位置 - 是我的主意工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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