We are currently developing an app where we'd like to change some system settings, with user permission of course. The android documentation says that to do this, you have to add the following permission:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Also, one has to explicitly ask the user to enable this permission. An excerpt from https://developer.android.com/reference/android/Manifest.permission#WRITE_SETTINGS says:
Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action
Settings.ACTION_MANAGE_WRITE_SETTINGS
. The app can check whether it has this authorization by callingSettings.System.canWrite()
.
Up until this point, it is quite clear. However, when the permission is added to the AndroidManifest.xml file, Android Studio complains that "Permission is only granted to system apps". Now, this is confusing since I haven't found any documentation stating that it is indeed only granted to system apps.
So, I'd like to ask if someone has encountered this issue, and if there is some kind of documentation that explains this in detail? Or am I simply missing something?
What Does Android Permission Use_Full_Screen_Intent Mean? In Android 10 and higher, and when using alerts with full screen intent, an app can request USE_FULL_SCREEN_INTENT in its manifest file for this permission. This permission acts as a normal permission, so it is automatically granted to the app that asks.
App permissions help support user privacy by protecting access to the following: Restricted data, such as system state and a user's contact information. Restricted actions, such as connecting to a paired device and recording audio.
Unfortunately, it seems that not a few Android apps have found ways to ignore the user's explicit instructions in this regard. A research conducted by the International Computer Science Institute revealed that up to 1,325 apps on Google Play Store continued gathering data regardless of their permissions settings.
As stated by user passsy in the stackoverflow question provided by Brian, android.permission.WRITE_SETTINGS
has a android:protectionLevel
of "signature"
, which makes the permission unavailable for use in user applications since API level 23.
See https://developer.android.com/guide/topics/manifest/permission-element#plevel for the description of protection levels for permissions.
You need to get the user permission specifically from the user by that I mean you have to take the user to a screen where user can grant the permission to your app to have WRITE_SETTINGS permission.
So when ever you want to change system settings you have to check if the user has granted the permission or not like this:
private boolean checkSystemWritePermission() {
boolean retVal = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
retVal = Settings.System.canWrite(this);
Log.d("TAG", "Can Write Settings: " + retVal);
if(retVal){
///Permission granted by the user
}else{
//permission not granted navigate to permission screen
openAndroidPermissionsMenu();
}
}
return retVal;
}
private void openAndroidPermissionsMenu() {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + this.getPackageName()));
startActivity(intent);
}
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