I used the following code, my goal is API-15
android.provider.Settings.System.putInt(cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER);
When the code runs on the API-17 platform, I get warnings in logcat,
The wifi_sleep_policy setting has moved from android.provider.Settings.System to android.provider.Settings.Global, the value has not changed.
So, what I did after this, my APi-17 project goal was set and used this code
if(Build.VERSION.SDK_INT < 17) { android.provider.Settings.System.putInt(cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER); } else { android.provider.Settings.Global.putInt(cr, android.provider.Settings.Global.WIFI_SLEEP_POLICY, android.provider.Settings.Global.WIFI_SLEEP_POLICY_NEVER); }
As a result, I started getting the following SecurityException on the Api-17 platform
java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
Then I checked that the permission WRITE_SECURE_SETTINGS is intended only for system applications, and I could not compile my code with it, as if this permission was intended only for system applications.
So, I'm confused, there was a warning that I received earlier, it was wrong or something was wrong with my code, I want to make it compatible with API-17.
android
Ahmed
source share