Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Change wifi sleep policy programmatically?

I am making an app that relies on wifi while the phone screen is locked. However the user might set wifi to sleep when it is locked. Is there a way to disable this sleep policy programmatically?

like image 257
Max Mumford Avatar asked Oct 09 '22 17:10

Max Mumford


1 Answers

This code will set the sleep policy to never:

private void setNeverSleepPolicy(){
            ContentResolver cr = context.getContentResolver();
            int set = android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER;
            android.provider.Settings.System.putInt(cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, set);
        }
like image 196
Donal Rafferty Avatar answered Oct 12 '22 10:10

Donal Rafferty