Reputation: 145
In my application with targetSdkVersion as 23, while using the API Settings.System.putString().
Following error is being thrown and app crashes
"AndroidRuntime: java.lang.IllegalArgumentException: You cannot keep your settings in the secure settings."
After trying solution at
Can't get WRITE_SETTINGS permission
and granting the app write permission in screen opened by ACTION_MANAGE_WRITE_SETTINGS. The app still gets the error "You cannot keep your settings in the secure settings".
Is requesting the WRITE_SETTINGS permission now only for apps developed by OEMs ? Is there a solution possible ?
Sharing a sample code , tested on Nexus 5 device with M OS.
android:minSdkVersion="17"
android:targetSdkVersion="23"
uses-permission android:name="android.permission.WRITE_SETTINGS"
protected void onResume() {
super.onResume();
boolean canDo = Settings.System.canWrite(this);
if (false == canDo)
{
Intent grantIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
startActivity(grantIntent);
}
else
{
Settings.System.putString(this.getContentResolver(),
"test.hemant", "hemantval");
}
}
E/DatabaseUtils( 779): Writing exception to parcel
E/DatabaseUtils( 779): java.lang.IllegalArgumentException: You cannot keep your settings in the secure settings.
E/DatabaseUtils( 779): at com.android.providers.settings.SettingsProvider.warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk(SettingsProvider.java:1175)
E/DatabaseUtils( 779): at com.android.providers.settings.SettingsProvider.enforceRestrictedSystemSettingsMutationForCallingPackage(SettingsProvider.java:1030)
E/DatabaseUtils( 779): at com.android.providers.settings.SettingsProvider.mutateSystemSetting(SettingsProvider.java:906)
E/DatabaseUtils( 779): at com.android.providers.settings.SettingsProvider.insertSystemSetting(SettingsProvider.java:874)
E/DatabaseUtils( 779): at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:257)
E/DatabaseUtils( 779): at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
E/DatabaseUtils( 779): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
E/DatabaseUtils( 779): at android.os.Binder.execTransact(Binder.java:453)
D/AndroidRuntime(19935): Shutting down VM
Upvotes: 9
Views: 12258
Reputation: 1007369
Your code should fail on all versions of Android. If it worked prior to Android 6.0, that was a bug that apparently just got fixed.
Settings.System
is for platform-defined settings. You cannot put arbitrary settings in there, such as test.hemant
.
Upvotes: 6