I am building an android app to track my device, is it possible to turn location services on via code? I have searched for code to do so I have found some and on execution of code it gives some sort of security exceptions, and some threads here on stack overflow were saying that it is impossible to do so, If possible please provide code, if impossible why so?
Asked
Active
Viewed 2,039 times
-3
-
1https://stackoverflow.com/questions/29697725/enable-gps-programatically-android-without-navigating-to-the-location-settings/29697889#29697889 – CommonsWare May 17 '16 at 15:57
-
Actually that opens up a dialog box, i don't want to involve user in it, sort of anti theft app. – Adeeb Khalid Ch May 17 '16 at 16:01
-
We will not provide you code. YOu provide us code and we tell you what is wrong. We will not write code for you. Don't be lazy and write your own code. What have you done so far? – Neon Warge Jun 27 '17 at 06:55
1 Answers
6
is it possible to turn location services on via code?
Via Play Services' SettingsApi
, yes. Otherwise, no, except perhaps on rooted devices or in a custom malware-friendly ROM.
Actually that opens up a dialog box, i don't want to involve user in it
Then that is not possible.
I have searched for code to do so i have found some and on execution of code it gives some sort of security exceptions
There have been various security flaws in Android that, when exploited, would allow apps to enable GPS silently. AFAIK, all of them are fixed at this point.
if impossible why so?
Privacy.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491