This code:
Settings.System.putInt(context.getContentResolver(), POWER_KEY_DEFINITION, 1);
Generates the error:
java.lang.IllegalArgumentException: You cannot keep your settings in the secure settings.
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1595)
at android.provider.Settings$System.putStringForUser(Settings.java:1965)
at android.provider.Settings$System.putIntForUser(Settings.java:2070)
at android.provider.Settings$System.putInt(Settings.java:2064)
at com.example.sasho.timer2.MainActivity$1$1.run(MainActivity.java:155)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
Another SO question provides an answer to the same error, they say "Settings.System is for platform-defined settings. You cannot put arbitrary settings in there, such as test.hemant.".
But the thing is in my case this isn't an arbitrary system setting that I'm putting. I know it exists in the TV box I'm working on because before I tried in any way to write over it or create it I checked with the Settings.getInt method to get its value and indeed there was a value. I used the remote control to change the corresponding setting and getInt reflected the change. How can I resolve the error? I do have the WRITE_SETTINGS and WRITE_SECURE__SETTINGS permissions in my manifest.