1

I have an app that uses the GPS.

My problem is that when I get to the part that the GPS is looking for a signal and cant find it, it just keeps on searching. This kills the battery.

I used this:

this.locationManager.requestLocationUpdates(this.provider, 0,
                                            0, pendingIntent);

but it only sets the refresh rate. If the GPS is not locked than it keeps on trying.

I want it to stop after a few minutes of trying to get a lock.

What can I do?

porges
  • 30,133
  • 4
  • 83
  • 114
roiberg
  • 13,629
  • 12
  • 60
  • 91
  • 1
    try changing the second argument from 0 to something higher.. 0 tells the locationmanager to constantly check the gps status – Gryphius May 30 '12 at 07:49
  • 1
    and where are you try ? in Emulator ? in Office ? both these places will not going to return GPS Value, you have to try it in device with open sky field. – Lucifer May 30 '12 at 07:51
  • Locifer- i want to fix the problam of when it cant get a gps. i want it to stop looking for a signal it it cant find it. Gryphius - It was like you said before. still, if it has a lock, it refreshes acording to that line of code, if it cant lock it will try to forever. – roiberg May 30 '12 at 07:58
  • 1
    if you set it high enough, it should stop eventually, remember, the value is in milli seconds, try setting it to 300'000, iirc the gps will try to acquire a lock for about a minute, then stop, then retry 5 minutes later – Gryphius May 30 '12 at 08:09
  • can you please explain? as i understand it, it only states the time intervals between locks not how much time it can "try" to lock. – roiberg May 30 '12 at 08:15

1 Answers1

1

If you want to not check for new location frequently you have to specify minimum time and minimum distance. the structure is like this :

 public void requestLocationUpdates (String provider, long minTime, float minDistance, PendingIntent intent)

for more information check this link : http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28java.lang.String,%20long,%20float,%20android.app.PendingIntent%29

Edit : Sorry i don't understood your question. check this link, what you have to do is to set a timeout. Hope this help . How to time out GPS signal acquisition

Community
  • 1
  • 1
113408
  • 3,364
  • 6
  • 27
  • 54
  • again, im not talking about the frequent of the checking for location, im talking about the time it spends to search for GPS each time. i dont want him to do the searching for more than five minutes each time its searching. thanks for your answer anyway. – roiberg May 30 '12 at 09:08