1

I am trying to create my first android app in visual studio which is a simple widget that auto turns off location after a set period of time.I was wondering if there is a way to turn off the location service using location manager without having the need to go to device settings. Any help will be appreciated. Thanx

  • have a look at this http://stackoverflow.com/a/15426526/4450098 – Sagar Nayak Jul 05 '16 at 03:51
  • Location ?? Do you mean GPS ?? – Janki Gadhiya Jul 05 '16 at 04:09
  • You can't turn on/off location service programatically. You can only redirect user to device setting using intent. – Ketan Ahir Jul 05 '16 at 04:11
  • 1
    Possible duplicate of [Turning on and off GPS programmatically in android 4.0 and above?](http://stackoverflow.com/questions/15426144/turning-on-and-off-gps-programmatically-in-android-4-0-and-above) – SushiHangover Jul 05 '16 at 04:24
  • after doing plenty of research on internet I have come to conclusion that there no easy way to turn on or off the location in a third party app(on a unrooted phone). only possible solution is to redirect user to gps settings to allow them to disable or enable the gps. The solution some of you have provided doesn't work anymore due to privacy restrictions but used to work in older versions of android. I am still curious that if there is no clear way of achieving what I want, how does an app like tasker is able to control location within the app. –  Jul 05 '16 at 09:21

1 Answers1

0

You can use an Intent with the ACTION_LOCATION_SOURCE_SETTING as shown in this tutorial :

http://www.android-examples.com/enable-disable-gps-location-service-programmatically-android/

If it fits your needs, I will copy paste the source code here and credit the author.

Alexandre Martin
  • 1,472
  • 5
  • 14
  • 27
  • 1
    thanx alex for sharing the article but this doesnt meet my requirement as it redirects user to the settings page but in my case I am trying to schedule gps turn off after a set period of time which I have realized is not possible due to privacy restrictions. –  Jul 05 '16 at 21:06