How can I get the dreaded WRITE_SECURE_SETTINGS permission for my android app?

I need to be able to toggle the GPS receiver on and off

For privacy reasons, if nothing else, enabling or disabling any sort of location-tracking needs to be solely in the hands of the user via trusted applications, not at the request of arbitrary third parties.

So, if you wish to enable and disable GPS, create your own firmware that does what you need and load that firmware on whatever devices you wish. Or, contribute your changes to existing firmware mods (e.g., Cyanogen).

WRITE_SECURE_SETTINGS is required to be able to access secure settings

Correct.

I've searched around quite a bit, and every answer I saw pretty much said that no app outside of the system/firmware can get that permisssion.

Correct.

However, that is simply untrue.

No, it's pretty true.

There are several apps on the market that do exactly what I'm trying to (in regards to GPS)

They found a security loophole. I will take steps to help ensure this hole gets fixed.

but there are a bunch more that have the WRITE_SECURE_SETTINGS permissions

No, there are a bunch who ask for them. You can ask for whatever permission you want. What you ask for is what shows up in these listings. What you get is a different story.


Try this adb command, this will give permission at application run time

adb shell pm grant package android.permission.WRITE_SECURE_SETTINGS

Step to follow:

  1. Connect your device (Make sure USB Debugging enabled)

  2. Execute above adb command

  3. Install apk

It worked for me...


Just this. You can access the widget that every mobile have.

public void ativaGPS() {
        LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Intent intent = new Intent();
            intent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
            intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
            intent.setData(Uri.parse("3"));
            sendBroadcast(intent);
        }