Suman February 2016

Turning on and off GPS programmatically in all android version

I am working on a location based application. I want to turn on/off GPS through code. I found a solution from this [link]: Turning on and off GPS programmatically in android 4.0 and above? but app is crashing when i run this portion. Please guide me with proper solution.

Answers


CommonsWare February 2016

I want to turn on/off GPS through code

There is "enabled/disabled", and there is "on/off". "Enabled/disabled" determines whether any app can get GPS fixes. "On/off" determines whether the device is trying to get GPS fixes right now. GPS can only be "on" if it is "enabled".

If you request locations from the GPS_PROVIDER, and GPS is enabled, the GPS radio will turn on. If you stop requesting locations from the GPS_PROVIDER, and no other app is requesting locations from the GPS_PROVIDER, the GPS radio will turn off. Depending on how you configure your request for locations (e.g., once an hour), the GPS radio may turn off and on to save battery life, even while your request is outstanding. Hence, Android developers do not worry much about "on/off" — developers just request locations, and the hardware takes care of powering on and off the GPS radio as needed.

Your link really refers to "enabled/disabled". Android removed the ability for apps to enable and disable GPS back in Android 1.5, for privacy reasons. Malware authors have continued to try to find ways to get around this, because malware authors are not interested in user privacy. The link you cited was an exploit for a flaw in Android that allowed apps to enable and disable GPS. That exploit was fixed years ago. I am not aware of a current exploit that allows apps to enable and disable GPS.

Post Status

Asked in February 2016
Viewed 2,037 times
Voted 9
Answered 1 times

Search




Leave an answer