Possible Duplicate:
Enable GPS programatically like Tasker
I'm a beginner android developer.
I want enable and disable GPS with a click of a button, without running this intent:
intente in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(in);
that brings me in the setting menu.
Is there a method to enable or disable GPS as in the android "Power Control" widget?
Thanks
EDIT:
The widget that I said is in the android system (version 1.6 on forward). There is an application (siriusapplications.com/powercontrolplus) that make want I want do, and extend the android power control.. my question is: how this persor can manage this?? –
This example demonstrates how do I get enable/disable GPS programmatically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.
Get current location settingsTask<LocationSettingsResponse> task = client. checkLocationSettings(builder. build()); When the Task completes, your app can check the location settings by looking at the status code from the LocationSettingsResponse object.
I don't think there is a way to do so. See this question. You can also find a nice example here. Basically what you do is test if GPS is enabled and then navigate user to the appropriate settings page.
The widget you are referring to probably has direct access to the GPS driver. This means that will only work in the device at hand (or in a single family of devices).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With