1

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.

Stormtrooper
  • 107
  • 3
  • 8
  • 1
    https://stackoverflow.com/a/35285034/1568530 – Vladyslav Matviienko Nov 01 '18 at 12:51
  • Hello. I used that code but the same problem remains. Code dependent on the (Settings.System.canWrite(context)) clause executes so I guess I do have permission to write there.though still I get the same error – Stormtrooper Nov 01 '18 at 13:12
  • try to write some more commonly-used system settings, and check if it works. Probably there is just a list of settings which are allowed to write, and your `POWER_KEY_DEFINITION` is not in that list – Vladyslav Matviienko Nov 01 '18 at 13:15
  • POWER_KEY_DEFINITION is not in the usual list at all. But the device's manufacturer seems to have added it and is able to give it new values even though it's running android 7 – Stormtrooper Nov 01 '18 at 13:19
  • Hi, was you able to solve this issue? I got the same situation with another Samsung properties after upgrading from Android 12 to Android 11 – nikolayandr Nov 18 '22 at 20:36
  • Sorry I don't remember and there isn't a way for me to check. – Stormtrooper Nov 21 '22 at 18:45

0 Answers0