由Android 11中的设备所有者编程保存的WiFi无自动连接

发布于 2025-01-18 02:38:22 字数 675 浏览 5 评论 0原文

我在Android 11中有一个设备所有者应用程序,该应用程序负责配置WPA WiFi网络。我在代码中所做的基本上是以下):

val config = WifiConfiguration().apply {
            SSID = "\"Some-SSID\""
            allowedKeyManagement.set(KeyMgmt.WPA_PSK)
            preSharedKey = "\"some-password\""
            this.priority = 4
            status = WifiConfiguration.Status.ENABLED
            hiddenSSID = false
}
val networkId = wifiManager.addNetwork(config)
wifiManager.enableNetwork(networkId, true)

成功配置WiFi网络。在设置应用程序中,我可以看到网络已保存在那里。它还说它是由我的设备所有者保存的。但是,如果设备靠近网络,则不会自动连接。作为解决方法,我目前正在使用一个每30分钟产卵的工人,如果设备未连接到WiFi,则尝试连接到已保存的配置。这个解决方法目前正在起作用,但是我希望该系统为我处理。

我在配置中缺少什么,导致我的设备未连接到那些已配置的网络?

I have a device owner app in android 11 that is responsible for configuring WPA wifi networks. What I am doing in code basically is the following):

val config = WifiConfiguration().apply {
            SSID = "\"Some-SSID\""
            allowedKeyManagement.set(KeyMgmt.WPA_PSK)
            preSharedKey = "\"some-password\""
            this.priority = 4
            status = WifiConfiguration.Status.ENABLED
            hiddenSSID = false
}
val networkId = wifiManager.addNetwork(config)
wifiManager.enableNetwork(networkId, true)

This successfully configures the wifi network. In the settings apps, I can see that the networks are saved there; it also says that it was saved by my device owner. However, if the device is near to the network it doesn't connect automatically. As a workaround, I am currently using a worker that spawns every 30min and if the device isn't connected to a wifi, tries to connect to the saved configurations. This workaround is working for now, but I would like the system to handle that for me.

What am I missing in my configurations that is resulting in my device not connecting to those configured networks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文