WiFi锁不起作用,如何防止WiFi省电?
我做了一个应用程序,可以将手机变成网络摄像头,并使用手机连接将图像发送到互联网空间。
我正在使用广告活动,将警报管理器设置为每 5 或 15 分钟执行一次服务。 为了执行服务的整个执行,我执行了唤醒锁,但当服务完成时它会被删除。
所有这些在移动连接上都可以完美工作,但在 Wi-Fi 上则不然。
我在 wifi 选项中设置了 wifi 睡眠策略“从不”。 但一段时间后(并不总是相同),手机似乎进入省电模式:wifi 图标仍在状态栏上,但手机无法连接。即使我使用浏览器......所以我必须断开连接并手动重新连接。 logcat 中的消息:通知 conn 中断 (IOEx),关闭连接
即使手机已接通电源!!!
为什么? (1)
对由启动始终以唤醒锁运行的服务的活动形成的另一个应用程序进行实验。所以我添加了 wifi 锁来确保连接,但这种方法有时会运行,而其他方法则不会。总是相同的通知conn中断(IOEx),关闭连接
为什么? (2)
最后一个实验源自第一个应用程序(闹钟管理器),为了确保 wifi 不会进入睡眠/省电模式(巫婆??),我在执行后将手机设置为飞行模式代码的一部分,当循环开始时我将其关闭(连接打开)。这个工作两天没问题,但有时会工作(每小时或两个小时而不是每 5 分钟一次,或者有时一整天都不起作用,然后无故重新启动..)。那么,为什么飞行模式有时无法重新建立之前的 wifi 连接呢? (有时会这样?) (3)
该手机是配备 Originale 2.2 的 Samsung Galaxy ACE,并且始终插入充电。
I had done an app that transform the phone into a webcam and use the phone connection to send image to internet web space.
I'm using ad activity that set an Alarm Manager to execute a Service every 5 or 15 minutes.
To perform the entire execution of the Service I do a wake lock, but it's dropped when service finisched.
All this works perfect with mobile connection but doesn't do the same with wifi.
I had set in wifi options th policy "NEVER" for wifi sleep.
But after a time (not always the same) the phone seems to go on power save mode: wifi icon is yet on status bar but the phone isn't able to connect. Even is i use browser...so I must disconnect and manually reconnect.
The message in the logcat: notify conn break (IOEx), close connection
Even with phone plugged on power!!!
why? (1)
Doing experiment with another app formed by an activity that start a service always running with a wake lock. So i have added the wifi lock to be sure of connectivity, but also this method sometimes runs and some other not. Always the same notify conn break (IOEx), close connection
why? (2)
The last experiment is derived from the first app (alarm manager) and to be sure that the wifi doesn't go on sleep/power save mode (witch one??) i have turn the phone in airplane mode after the execution of the code and i turn it off (connection on) when the cycle begin. This work ok for two days, but after only sometimes it's work (each hour or two instead each 5 minutes, or sometimes doesn't work for an entire day and then restart without any reason..). So, why airplane mode sometimes doesn't re-establish the prewious wifi connection? (and some other times it does?) (3)
The phone is a Samsung Galaxy ACE with originale 2.2 and is ALWAYS plugged to charge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要防止设备进入“省电模式”,请尝试使用 WIFI_MODE_FULL_HIGH_PERF
直到 android 3.1 才公开。
但你仍然可以通过硬编码的方式使用它,WIFI_MODE_FULL_HIGH_PERF的值为3(int)。
我在 3.1 之前的设备上尝试过。它就像一个魅力!祝你好运!
To keep device from entering 'power save mode', try to use wifi lock of type WIFI_MODE_FULL_HIGH_PERF
It's not public available until android 3.1.
but you can still use it by hard-coding, the value of WIFI_MODE_FULL_HIGH_PERF is 3(int).
I tried it on a pre-3.1 device. It works like a charm! good luck!