Reputation: 1407
I'm trying to modify some settings on my phone through the app but I keep getting this error:
java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
I have added this permission to my manifest but the error still remains. Here is a snippet from my manifest:
<uses-permission
android:name="android.permission.MEDIA_CONTENT_CONTROL"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
android:maxSdkVersion="11" />
What is the problem here?
Upvotes: 1
Views: 9187
Reputation: 8926
Android doc says,
android:maxSdkVersion
The highest API level at which this permission should be granted to your app. Setting this attribute is useful if the permission your app requires is no longer needed beginning at a certain API level.<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
This way, beginning with API level 19, the system will no longer grant your app the WRITE_EXTERNAL_STORAGE permission.
In which SDK version do you run this code?
For Android version 11 & below, permission will be granted as per your code.
If you do not want to limit the permission with respect to particular sdk versions, remove the maxSdkVersion attribute.
Upvotes: 4
Reputation: 5890
try like:
<uses-permission
android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-sdk
android:maxSdkVersion="11"
android:minSdkVersion="7"
android:targetSdkVersion="9" />
Note: It is not good to use android:maxSdkVersion
in manifest. You can remove it.
Upvotes: 5