不工作时启用 WiFi 的设置命令
我创建了一个计时器,它将检查 wifi 是否启用(WiFiManager.isWifiEnabled()),如果未启用,则调用 WiFiManager.setEnabled() 方法来启用设备的 WiFi,它会在应用程序后台的 onCreate() 方法中启动计时器服务,计时器将每 1 秒运行一次以验证 wifi 是否启用。
当设备处于活动状态时,应用程序可以正常运行,但是当设备进入睡眠模式/锁定状态时,即使我引入计时器来设置每 1 秒启用 wifi,wifi 也会断开连接。因此,即使设备进入睡眠/锁定模式,也无法找到保持 wifi 打开的方法。
I created a timer which will check whether wifi is enabled or not (WiFiManager.isWifiEnabled()) and if it is not enabled then calling WiFiManager.setEnabled() method to enable device's WiFi, it starts timer in onCreate() method of Application's background service, timer will run every 1 seconds to verify wifi enabled or not.
When device is in active state,app runs properly but when device goes to sleep mode/locked state, wifi is getting disconnected even though I introduce timer to set wifi enabled in every 1 second. So not able to find out the way to keep wifi turned on even device goes to sleep/locked mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题是,当设备锁定时,android会进入睡眠模式。这会将所有服务置于后台。
我不确定是否可以锁定 wifi 连接。
Mark Murphy 创建了唤醒服务演示,以展示如何在设备睡眠时唤醒服务。也许这可以解决你的问题,但我不确定。
your problem is, that android will enter the sleep mode when the device is locked. this will put all services into the background.
i´m not sure if it is possible to lock the wifi connection.
Mark Murphy created the wakeful service demo to show how to wake up services while the device is sleeping. maybe this could solve your problem but i´m not sure.