I was using following code , my target 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 platform API-17 I get warnigns in the logcat,
Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.
So what I did after that was set my project target to APi-17 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 following SecurityException in platform Api-17
java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
Then I checked that WRITE_SECURE_SETTINGS permission is only for system apps and I was not able to compile my code with it, as if this permission is for system apps only.
So I am confused was the warning that I got earlier was wrong or is there anything wrong with my code, I want to make it compatible it with API-17.