gpt4 book ai didi

Android 8 (Oreo) WifiManager 重新连接方法超时

转载 作者:行者123 更新时间:2023-11-29 02:35:07 25 4
gpt4 key购买 nike

我有一个问题。我正在忙的应用程序目前有一个奇怪的问题。我使用以下库:WiseFly这是一个简单的 wifi 管理器包装器

我的应用管理 WiFi 网络。它将添加到保存的网络并根据用户与我的应用程序的交互连接到它。它适用于所有版本的 android,除了我的 Pixel 上的 Android Oreo。

它在包装器内部的以下行超时:

getWifiManager().disconnect();
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);
getWifiManager().reconnect();

最后一行是问题所在。如果我进入 android 上的网络设置,我会看到保存的网络,但也不会从 android 内部连接。有什么想法可以解决这个问题吗?

这是用于添加网络的代码:

/**
* To generate a configuration for a WPA2 network
*
* @param ssid The ssid for the WPA2 network's configuration
* @param password The password for the WPA2 network's configuration
*
* @return WifiConfiguration - The WPA2 network configuration
*/
public WifiConfiguration generateWPA2NetworkConfiguration(String ssid, String password) {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = mSSIDUtil.convertSSIDForConfig(ssid);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
return wifiConfiguration;
}

如有任何帮助,我们将不胜感激。

谢谢

最佳答案

试试这个

// Allow a previously configured network to be associated with.
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);

// Reconnect to the currently active access point, if we are currently disconnected.
getWifiManager().reconnect();

// wait until reconnect process is completed
Thread.sleep(3000);

关于Android 8 (Oreo) WifiManager 重新连接方法超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47530720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com