I know. Don't do this. I don't care. It's for a root app.
The app is installed to /system/app/
with 0777
permission
I was previously using:
ContentResolver cr = context.getContentResolver();
Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, !isGpsOn);
This is how I'm trying it on 4.4 since that was deprecated:
int value;
if (isGpsOn)value = Settings.Secure.LOCATION_MODE_OFF;
else value = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
Settings.Secure.putInt(cr, Settings.Secure.LOCATION_MODE, value);
And it is silently failing (according to some user reports). How can I properly toggle GPS with Android 4.4 from an app in System folder?
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.
Programmatically we can turn on GPS in two ways. First, redirect the user to location settings of a device (by code) or another way is to ask to turn on GPS by GPS dialog using LocationSettingsRequest and SettingsClient.
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.
“Mock Location” is a hidden developer setting in the Android operating system that allows a device owner to set any GPS location for testing purposes. Despite the fact that this is a developer setting, anyone can use it just by clicking a couple of buttons in device settings.
Don't do this. :)
Check the code for GPS TOGGLER
GPS toggle widget for Android rooted devices. It wrks well even for those ROMs and kernels, other software failed.
With your code, just checking:
Hope you declared the following permissions in your manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
I had used this on rooted LG Optimus, android 4.0/4.1. Reportedly this may no longer work but i am not sure about it for all devices and o.s.:
Switch it ON/OFF with a flag check and this code:
try {
Settings.Secure.putString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED, String.format ("%s,%s",
Settings.Secure.getString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED), LocationManager.GPS_PROVIDER));
} catch(Exception e) {}
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