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.
How to set the Permission WRITE_SECURE_SETTINGS in android?
WRITE_SECURE_SETTINGS is not available to applications. No app outside of the system/firmware can get that permisssion.
Please check this answer
Problems with checking for WRITE_SECURE_SETTINGS permission in my app
The
getContext()
andgetActivity()
method is used inFragment
to getContext
Remove getContext()
and getActivity()
And use this
and MainActivity.this
to get Context
in your activity
Use this
int checkVal = checkCallingOrSelfPermission(requiredPermission);
instead of this
int checkVal = getContext().checkCallingOrSelfPermission(requiredPermission);
SAMPLE CODE
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String requiredPermission = "android.permission.WRITE_SECURE_SETTINGS";
int checkVal = checkCallingOrSelfPermission(requiredPermission);
if (checkVal == PackageManager.PERMISSION_GRANTED) {
}
Toast.makeText(this, "WRITE_SECURE_SETTINGS has been granted to the application. You may now continue!",
Toast.LENGTH_LONG).show();
if (checkVal == PackageManager.PERMISSION_DENIED) {
}
Toast.makeText(this, "WRITE_SECURE_SETTINGS has not been granted to the application. Please grant access to continue.",
Toast.LENGTH_LONG).show();
}
}
WRITE_SECURE_SETTINGS + root
Am I missing something?
You are missing the WRITE_SECURE_SETTINGS
permission.
I am asking for the WRITE_SECURE_SETTINGS permission, so that can't be it.
AFAIK, being root has nothing to do with permissions, directly. To hold WRITE_SECURE_SETTINGS
, your app must either be signed by the same signing certificate that signed the firmware or be installed on the system partition. Being root is neither of those things.
When I set the ringermode to RINGER_MODE_SILENT, the phone still vibrates and the icon in the menu is set to the 'vibrate' icon
Try this :
AudioManager audio = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audio.setRingerMode(0);
Android Manifest file:
<application>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</application>
Android mock location providers not cleaned from LocationManager
Think I found a way to get an accurate reading whether GPS/Network provider are enabled or not:
ContentResolver contentResolver = context.getContentResolver();
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.GPS_PROVIDER);
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.NETWORK_PROVIDER);
Related Topics
Auto Start Application After Boot Completed in Android
Android: Broadcastreceiver Intent to Detect Camera Photo Taken
How to Set Up Multiple Listeners for One Event
How to Create an Android Service That Listens for Hardware Key Presses
Android - How to Check If Developer Option Is Enabled
Android Studio 1.0.2 Not Building App:Mergedebugresources Error
Is Arm64-V8A Compatible with Armeabi-V7A
Android Studio Cannot Resolve R in Imported Project
Can't Access "Findviewbyid" in Asynctask
Android: How to Create Fade-In/Fade-Out Sound Effects for Any Music File That My App Plays
Retrofit2: Modifying Request Body in Okhttp Interceptor
Saving Arraylists in SQLite Databases
Getting All the Total and Available Space on Android
Android Systemui Glitches in Lollipop
Mediaplayer.Setdatasource() and Prepare() Not Working - Android
How to Handle System_Alert_Window Permission Not Being Auto-Granted on Some Pre-Marshmallow Devices