Android Periodic GPS location updates with AlarmManager inside a Service

前端 未结 2 1607
迷失自我
迷失自我 2020-12-15 01:38

I read a lot of questions on here but couldn\'t figure out what the problem is.

I\'m writing a field service application for Android. In one of the Activities (MyAct

相关标签:
2条回答
  • 2020-12-15 02:17

    try this:

    AlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,,,);
    

    I am doing for get one's current location with GPS, but my project works every 10 seconds. I have no idea now. And my code :

    AlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),6000000,pi);
    
    0 讨论(0)
  • 2020-12-15 02:21

    First, you cannot register for location updates, then shut down the service. At best, you will leak threads. At worst, Android will terminate your process (thinking there is nothing running in it) and you will not get the update. Also, GPS takes a while to warm up, so you might not get a fix within 20 seconds, particularly in an urban setting. Also, you have to make sure the device stays awake while you are trying to collect a fix.

    As a result, getting periodic location fixes in the background is a rather complicated problem.

    I wrote a now-discontinued LocationPoller to try to address this, and another developer has forked and extended it. You could try the fork or simply use it as a source of ideas.

    0 讨论(0)
提交回复
热议问题