唤醒锁似乎不起作用
我正在开发一个应用程序,其中我需要 TCP 连接才能保持活动状态。我已经实现了一种乒乓球系统来做到这一点。当屏幕打开时它工作得很好,但是当屏幕关闭时,手机会在一段时间后停止响应 ping。我已经创建了 Wi-Fi 唤醒锁,但我仍然遇到同样的问题。
这是我的代码:
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();
}
}
}
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须从此处使用 SCREEN_DIM_WAKE_LOCK/PARTIAL_WAKE_LOCK 标志获取 PowerLock。
You have to acquire PowerLock from here with SCREEN_DIM_WAKE_LOCK/PARTIAL_WAKE_LOCK flag.