App Inventor and Java

How to toggle GPS from within App Inventor calling a Java app

As you know, to toggle GPS from within App Inventor directly is not possible, you only can open the settings window for the user to enable/disable it. And this also is generally not possible with the Android SDK, why see also here: "You can't for security/privacy reasons, you have to forward to location preferences screen and let the user enable/disable it."

However for Android 2.x devices, the GPS can be toggled by exploiting a bug in the power manager widget!
I now prepared a small Java app Toggle GPS you can call with the Activity Starter from App Inventor to toggle GPS. I tested successfully with a HTC Desire running Android 2.2 and a HTC Desire S running Android 2.3.5. It did not work (as expected) on Samsung Galaxy Tab running Android 3.2.
Thank you Ben H for the example code.

Toggle GPS doesn't need any permissions. You also can call Toggle GPS directly (without App Inventor) and it will enable/disable the GPS. As already mentioned this will work on Android 2.x devices only.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.


App Inventor blocks


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:

Thank you! Taifun

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.

Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact