【发布时间】:2019-03-23 14:26:24
【问题描述】:
在 Android 8.1.0 及更高版本上,我遇到了一个重大问题。
当使用enableNetwork 连接到没有互联网的网络时,Android 会在几秒钟后决定将设备恢复到之前的网络。
我有意连接到所需的网络,并计划使用bindToNetwork 来确保所有流量都通过网络,但是 Android 似乎忽略了绑定并在之后很快断开连接。
不幸的是,我在这里看到了这个问题的一些排列方式,但都没有得到答复。
我正在使用以下代码创建与网络的连接。我可以看到网络正在连接。
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = desiredSSID;
if (desiredNetwork.has("password")) {
conf.preSharedKey = String.format("\"%s\"", desiredNetwork.get("password"));
}
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int networkID = wifiManager.addNetwork(conf);
wifiManager.enableNetwork(networkID, true);
是否有可用的选项来禁用此行为,因为我有意连接到没有可用互联网的网络。
谢谢。
【问题讨论】:
标签: android wifimanager android-connectivitymanager