Android - Any way to have Location services turn itself off after a time limit?
That might be solved using one of the many automation apps. I myself prefer tasker here, but YMMV (and Tasker doesn't come for free) – llama might be capable of the same.
What I do here is creating a profile like this:
- Condition: App (select the apps you want to use GPS with)
- Task: GPS On
- optional exit task: GPS Off
That way GPS by default is off, but automatically gets turned on whenever you launch one of the selected apps and have them running in foreground. It would automatically be turned off once you exit that app, or have any other app running in foreground. The "exit task" is optional as Tasker restores the conditions from before the profile became active.
For other alternative automation apps, you're also welcome to take a look at my list here.
As Izzy said in the answer, Tasker is a great choice but it's not free for anyone. I tried AutomateIt(Free) and it gets the job done.
Edit: This answer is successfully tested on Android 4.2.1, without giving root access to AutomateIt. However, on Android 4.4.2, COS12 (Android 5.0.2) and CM12.1 (Android 5.1.1, build: YOG7DAO1K6), the relevant options were not visible until I restarted the app with root access. This fact came to my notice through this comment by jonatr.
- Install and launch AutomateIt.
- Go to My Rules → All, and see if you need any predefined rules. If you don't then either disable or delete by tapping each entry once and selecting the desired option.
+corresponding to My Rules tab → Application Status Trigger → tap lens icon and choose your app (Maps here) → check Application Activated→ Next → Enable/Disable GPS Action → Enable GPS → Next → choose Default or No (to show or not, a toast whenever automation will be triggered) → tap floppy icon at the top to save everything.
- Repeat steps 2-4 except that uncheck Application activated in step 3 this time.
Now you can open the Maps and Location will be enabled. You close the Maps and Location will be disabled. You can do more with it if you certainly want to disable Location (say 10 minutes) after minimizing the Maps.
Honestly, I'll prefer Tasker because I need fewer steps and I know it doesn't hog my battery. Check it out if AutomateIt eats the battery quite a lot.
As said, most automation apps can perform this task, Automate is another free alternative. Here's some user-made automations for toggling the GPS when viewing Google Maps:
A rooted device is required, but it may be possible to workaround using UI automation.