Wifi 刚刚进入 IDLE
我编写了一些使用 Wifi 作为可能的互联网连接介质的软件。 不过我确实注意到,经过一段时间(我猜大约 15-20 分钟)后,设备进入省电模式(无论如何,当屏幕变黑时),Wifi 连接将简单地断开,即使它是仍在使用:( 这在 ADP 2 上(因此是带有 Android 1.6 的 Google Ion)... 我能够得到以下日志:
06-10 15:04:27.009: DEBUG/WifiService(72): got ACTION_DEVICE_IDLE
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=0 state=8]
06-10 15:04:27.079: VERBOSE/WifiStateTracker(72): Changing supplicant state: COMPLETED ==> DORMANT
06-10 15:04:27.079: DEBUG/WifiStateTracker(72): Deconfiguring interface and stopping DHCP
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=-1 state=8]
06-10 15:04:27.139: WARN/Smack/Packet(169): notify conn break (IOEx), close connection
06-10 15:04:27.139: DEBUG/Smack(169): [XMPPConn] close connection, notifyClosed=false
06-10 15:04:27.139: ERROR/MediaPlayer(390): error (1, -17)
06-10 15:04:27.139: ERROR/MediaPlayer(390): Error (1,-17)
06-10 15:04:28.109: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DRIVER-STATE STOPPED]
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): New network state is DISCONNECTED
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): Changing supplicant state: DORMANT ==> DORMANT
06-10 15:04:28.189: INFO/MediaUploader(199): No need to wake up
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4484259ms
06-10 15:04:28.289: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:28.299: DEBUG/GpsLocationProvider(72): state: CONNECTING apnName: iinternet reason: null
06-10 15:04:32.979: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:33.029: DEBUG/GpsLocationProvider(72): state: CONNECTED apnName: iinternet reason: null
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4479355ms
06-10 15:04:33.129: INFO/MediaUploader(199): No need to wake up
06-10 15:04:33.299: INFO/ActivityManager(72): Stopping service: com.android.mms/.transaction.TransactionService
06-10 15:04:33.339: ERROR/TransactionSettings(156): Invalid APN setting: MMSC is empty
06-10 15:04:33.419: INFO/ActivityManager(72): Stopping service: com.android.providers.downloads/.DownloadService
06-10 15:04:38.309: DEBUG/dalvikvm(199): GC freed 301 objects / 19232 bytes in 92ms
06-10 15:04:43.349: DEBUG/dalvikvm(216): GC freed 1430 objects / 84920 bytes in 121ms
06-10 15:04:48.319: DEBUG/dalvikvm(156): GC freed 323 objects / 15152 bytes in 96ms
这是某种已知的错误/功能吗?如果是这样如何绕过它? 还有什么方法可以实际拦截此事件,然后如何忽略它或重新设置 wifi 连接? 提前致谢
I have written some software which uses Wifi as a possible internet-connection medium..
I did notice though, that after some time (I am guessing around the 15-20 minutes) after the device has gone into power save mode (anyways when the screen has gone black) the Wifi connection will simply be dropped, even though it is still being used :( This on a ADP 2 (thus a Google Ion with Android 1.6)...
I was able to get the following Log :
06-10 15:04:27.009: DEBUG/WifiService(72): got ACTION_DEVICE_IDLE
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=0 state=8]
06-10 15:04:27.079: VERBOSE/WifiStateTracker(72): Changing supplicant state: COMPLETED ==> DORMANT
06-10 15:04:27.079: DEBUG/WifiStateTracker(72): Deconfiguring interface and stopping DHCP
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=-1 state=8]
06-10 15:04:27.139: WARN/Smack/Packet(169): notify conn break (IOEx), close connection
06-10 15:04:27.139: DEBUG/Smack(169): [XMPPConn] close connection, notifyClosed=false
06-10 15:04:27.139: ERROR/MediaPlayer(390): error (1, -17)
06-10 15:04:27.139: ERROR/MediaPlayer(390): Error (1,-17)
06-10 15:04:28.109: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DRIVER-STATE STOPPED]
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): New network state is DISCONNECTED
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): Changing supplicant state: DORMANT ==> DORMANT
06-10 15:04:28.189: INFO/MediaUploader(199): No need to wake up
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4484259ms
06-10 15:04:28.289: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:28.299: DEBUG/GpsLocationProvider(72): state: CONNECTING apnName: iinternet reason: null
06-10 15:04:32.979: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:33.029: DEBUG/GpsLocationProvider(72): state: CONNECTED apnName: iinternet reason: null
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4479355ms
06-10 15:04:33.129: INFO/MediaUploader(199): No need to wake up
06-10 15:04:33.299: INFO/ActivityManager(72): Stopping service: com.android.mms/.transaction.TransactionService
06-10 15:04:33.339: ERROR/TransactionSettings(156): Invalid APN setting: MMSC is empty
06-10 15:04:33.419: INFO/ActivityManager(72): Stopping service: com.android.providers.downloads/.DownloadService
06-10 15:04:38.309: DEBUG/dalvikvm(199): GC freed 301 objects / 19232 bytes in 92ms
06-10 15:04:43.349: DEBUG/dalvikvm(216): GC freed 1430 objects / 84920 bytes in 121ms
06-10 15:04:48.319: DEBUG/dalvikvm(156): GC freed 323 objects / 15152 bytes in 96ms
Is this some kind of known bug/feature ? If so how to get around it ?
Also is there someway to actually intercept this EVENT and then soimehow ignore it or re-setup a wifi connection ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要创建一个 wifi 锁。具体操作方法如下:
请注意,您只应在主动使用 wifi(即下载大文件)时创建 wifi 锁,否则将不必要地影响电池寿命。
You need to create a wifi lock. Here is how you do it:
Note you should only create a wifi lock when you're actively using wifi (i.e. downloading a large file), otherwise you will needlessly impact battery life.
当我调用 WifiLock.acquire() 时,出现 SecurityException。我的清单中是否缺少使用权限,或者是否需要在代码中事先检查某些内容?
我假设这与 wifi 设置页面中的高级设置设置为“从不”有关。
I get a SecurityException when I call WifiLock.acquire(). Am I missing a uses-permission in my manifest or is there something I need to check beforehand in code?
I'm assuming it has to do with the advanced settings in the wifi settings page set to NEVER.
获取 Wi-Fi 锁并不是解决此问题的首选解决方案。 Wi-Fi 锁的目的是仅在您主动访问网络(即下载文件)时才保留它。例如,Skype 和 Google HangOut 不会获取并保留 Wi-Fi 锁定。你应该按照 Martin Molnar 在上面的评论中所说的去做。您应该让用户决定是否允许他的设备(以及设备上的应用程序)在显示屏关闭时通过“睡眠时 WiFi 唤醒”设置保持与 Wi-Fi 的连接。如果您绝对坚持您的应用程序应在显示屏关闭后 15 分钟内保持 Wi-Fi 开启,即使用户将“睡眠时 WiFi 唤醒”设置为“否”,那么您应该采用部分唤醒锁定。同样,Skype 不采用部分唤醒锁定。
如果您确实想要一个可以异步接收数据/通知的灵活应用程序,那么您应该设置 GCM 推送通知。
Getting a Wi-Fi lock is not the preferred solution to this. The intention of the Wi-Fi lock is to only hold it when you're actively accessing the network, i.e. downloading a file. E.g. Skype and Google HangOut don't take and keep the Wi-Fi lock. You're supposed to do what Martin Molnar said in his comment above. You're supposed to let the user decide if he wants to allow his device (and your App on his device) to stay connected to Wi-Fi when the display is off via the "WiFi awake while in sleep" setting. If you absolutely insist that your App should keep Wi-Fi on even 15min after the display is off, even if the user set "WiFi awake while in sleep" to "no" then you're supposed to take the Partial Wake Lock. Again Skype does not take the Partial Wake Lock.
If you really want to have a slick App that can receive data/notifications asynchronously then you should set up GCM push notifications.