The behavior of the settings. System API in Android API Level 23

In my application with targetSdkVersion as 23 using API Settings.System.putString ().

The following error is reset: the application crashes "AndroidRuntime: java.lang.IllegalArgumentException: you cannot save your settings in safe settings."

After trying to resolve the site, Unable to obtain permission WRITE_SETTINGS
and granting permission to record the application on the screen opened by ACTION_MANAGE_WRITE_SETTINGS. The application still receives the error message "You cannot save your settings in secure settings."

Now requests permission WRITE_SETTINGS only for applications developed by OEMs? Is a solution possible?

Exchange of sample code tested on a Nexus 5 device with M OS.

Android Manifest Snippet:

android:minSdkVersion="17" android:targetSdkVersion="23" uses-permission android:name="android.permission.WRITE_SETTINGS" 

Code snippet:

 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"); } } 

Log Stack:

 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 
+5
source share
1 answer

Your code should fail on all versions of Android. If it worked before Android 6.0, it was a bug that apparently had just been fixed.

Settings.System is for settings defined by the platform. You cannot set arbitrary settings, for example test.hemant .

+4
source

Source: https://habr.com/ru/post/1233057/


All Articles