Question

I am using Gps and fetching location and sending to server after each 10 minutes but do to Gps ,battery draining.So for this i want that after each 10 minutes Gps should on and fetch location and after this Gps should off itself.

Était-ce utile?

La solution

Set an Alarm via AlarmManager for every 10 minutes. In the alarm, call locationManager.requestSingleUpdate for the GPS provider. That will turn on the GPS long enough to get a single fix, then turn it off (unless some other program is using it). When it gets a fix it will call you via the callback you register in requestSingleUpdate. Then you can do whatever you need to with the result (such as sending it to a server via an AsyncTask).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top