简体   繁体   English

Android:即使使用 WifiLock 也会关闭 Wifi

[英]Android: Wifi is turned off even with WifiLock

I have a foreground service that runs as long as I have a Wifi connection.我有一个前台服务,只要我有 Wifi 连接就可以运行。 During the duration of the service it holds a WifiLock.在服务期间,它持有一个 WifiLock。 Everything works fine until I turn off the screen and wait about 15 minutes.一切正常,直到我关闭屏幕并等待大约 15 分钟。 My socket that I hold then throws a connection timeout exception because the Wifi disconnects (I see it in the logs and my android.net.wifi.STATE_CHANGE broadcast receiver is started).我持有的套接字然后引发连接超时异常,因为 Wifi 断开连接(我在日志中看到它并且我的 android.net.wifi.STATE_CHANGE 广播接收器已启动)。 The Wifi then proceeds and gets a new connection. Wifi 然后继续并获得新的连接。

Bwt the same thing happens if I remove my WifiLock and instead change the Wifi sleep policy to "never".如果我删除我的 WifiLock 并将 Wifi 睡眠策略更改为“从不”,也会发生同样的事情。 But without either the wifi is just turned off until the screen is unlocked.但是没有任何一个,wifi都会被关闭,直到屏幕解锁。

Couldn't find anything that solved this problem, any suggestion/workarounds are appreciated.找不到任何解决此问题的方法,感谢任何建议/解决方法。 If not, my service will just use the new connection and I will have to build around this issue.如果没有,我的服务将只使用新连接,我将不得不围绕这个问题进行构建。

Using a Galaxy Tab.使用 Galaxy Tab。

As ahmedre noted this is a bug with Android.正如 ahmedre 所指出的,这是 Android 的错误。 I now create a response from the client to make sure the message was received.我现在创建来自客户端的响应以确保收到消息。 Otherwise try again momentarily.否则请稍后再试。 This is to get around the problem of sending a message when the Wifi just died.这是为了解决Wifi刚死时发送消息的问题。

Update更新

I have not seen this particular issue on newer devices.我没有在较新的设备上看到这个特殊问题。 Originally this behavior occured on the Galaxy Tab.最初,此行为发生在 Galaxy Tab 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使在Android中关闭了屏幕,如何保持应用状态? - How to keep app status even if screen is turned off in Android? 即使关闭wifi也可以“连接” - “Connected” even when wifi is off 即使设置已关闭,jOOQ 也会用引号将函数括起来 - jOOQ surrounds functions with quotes even if the setting is turned off Spring 使用 CSRF 令牌的安全性,即使未指定并关闭 - Spring Security using CSRF token even though not specified and turned off 检测屏幕关/开并在Android中更改wifi状态 - Detect screen off/on and change wifi state in Android Android Wear OS 关闭 Wifi - Android Wear OS turn off Wifi Android 关闭飞行模式时应用程序崩溃 - Android App crushes when airplane mode is turned off 在android studio中更改和关闭连接之前更新数据库字段 - Update database field before the connections changed and turned off in android studio 如何锁定设备,但防止屏幕在android中关闭? - how to lock device but prevent the screen to be turned off in android? 即使在用户强行关闭gps的情况下,如何使用fusionloaction api在后台获取位置信息? - How to get location information in background using fusedloaction api even when gps is turned off forcefully by the user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM