开发者

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 = getS开发者_如何学运维ystemService(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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜