How can I get the scary WRITE_SECURE_SETTINGS permissions for my Android app?

I need to turn the GPS receiver on and off, and WRITE_SECURE_SETTINGS is required to access the secure settings. I searched around quite a bit, and every answer that I saw pretty much said that no application outside the system / firmware can get this edit.

However, this is simply not true. There are several applications on the market that do exactly what I am trying (regarding GPS), but there is another group that has WRITE_SECURE_SETTINGS permissions. For example:

Advanced controls

Switchpro

Stream profile

So how can this be done?

+8
android permissions gps
source share
3 answers

I need to turn on and off the GPS receiver

For privacy reasons, if nothing else, enabling or disabling any location tracking should not be exclusively in the hands of the user through trusted applications, and not at the request of arbitrary third parties.

So, if you want to turn GPS on and off, create your own firmware that will do everything you need and download this firmware on any devices you want. Or make changes to existing firmware modes (for example, Cyanogen).

Accessing secure settings requires WRITE_SECURE_SETTINGS

Correctly.

I searched around quite a bit, and every answer that I saw pretty much said that no application outside the system / firmware can get this edit.

Correctly.

However, this is simply not true.

No, its true.

There are several applications on the market that do exactly what I am trying (regarding GPS)

They found a security loophole. I will take steps to help eliminate this hole.

but there is another group that has WRITE_SECURE_SETTINGS permissions

No, there is a group that asks them. You can request any permission. What you ask for is what appears on these lists. What you get is a completely different story.

+23
source share

Try this adb command, it will give permission at application startup

adb shell pm grant package android.permission.WRITE_SECURE_SETTINGS 

Step:

  • Connect the device (make sure USB debugging is enabled)

  • Run on adb command

  • Install apk

It worked for me ...

+12
source share

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

 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); } 
0
source share

All Articles