Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wake lock does not seem to work

I'm developing an app in which i need the TCP connection to stay alive. I've implemented a kind of ping/pong system to do this. It works perfectly when the screen is on, but when it goes of the phone stops responding to the pings after a while. I've created a Wi-Fi wake lock but i'm still experiencing still the same problem..

This is my code:

private static WifiManager wm = getSystemService(this.WIFI_SERVICE);
private static WifiLock wl = null;

public static void lock(){
    wl = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , App.TAG);
    if(!wl.isHeld()){
        wl.acquire();
    }
}

public static void unlock(){
    if(wl != null){
        if(wl.isHeld()){
            wl.release();
        }
    }
}

Any ideas?

like image 575
shuwo Avatar asked Nov 06 '22 12:11

shuwo


1 Answers

You have to acquire PowerLock from here with SCREEN_DIM_WAKE_LOCK/PARTIAL_WAKE_LOCK flag.

like image 163
Damian Kołakowski Avatar answered Nov 12 '22 19:11

Damian Kołakowski