gpt4 book ai didi

Android连接到EAP-AKA WiFi

转载 作者:行者123 更新时间:2023-11-29 20:01:42 30 4
gpt4 key购买 nike

我需要一个简单的代码,说明如何从移动应用程序连接到安全 WIFI (EAP-AKA)。我有以下代码,但我不知道它是否正确,也不知道如何使用它。如果有人有示例代码,那就太好了。

  // Initialize the WifiConfiguration object
WifiConfiguration wifi = new WifiConfiguration();


WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
wifi = new WifiConfiguration();
wifi.SSID = ssid;
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
enterpriseConfig.setIdentity(userName);
enterpriseConfig.setPassword(passWord);
enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.AKA);
wifi.enterpriseConfig = enterpriseConfig;

最佳答案

我找到了答案,并决定提出来,可能对任何人都有帮助

示例代码应用程序可以在我的存储库中找到 https://github.com/malah-code/Android-Eap-Aka-Sample

代码

// Initialize the WifiConfiguration object
logThis("attemp to connect\n");
mProgressView.refreshDrawableState();
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
WifiConfiguration wifi = new WifiConfiguration();
wifi.SSID = mSSIDView.getText().toString();
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.AKA);
wifi.enterpriseConfig = enterpriseConfig;

logThis("finding saved WiFi\n");
wifi.networkId = ssidToNetworkId(wifi.SSID);

if (wifi.networkId == -1) {
logThis("WiFi not found - adding it.\n");
wifiManager.addNetwork(wifi);
} else {
logThis("WiFi found - updating it.\n");
wifiManager.updateNetwork(wifi);
}
logThis("saving config.\n");
wifiManager.saveConfiguration();

wifi.networkId = ssidToNetworkId(wifi.SSID);
logThis("wifi ID in device = " + wifi.networkId + "\n");

SupplicantState supState;
int networkIdToConnect = wifi.networkId;
if (networkIdToConnect >= 0) {
logThis("Start connecting...\n");

// We disable the network before connecting, because if this was the last connection before
// a disconnect(), this will not reconnect.
wifiManager.disableNetwork(networkIdToConnect);
wifiManager.enableNetwork(networkIdToConnect, true);


WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
logThis("WifiWizard: Done connect to network : status = " + supState.toString());
} else {
logThis("WifiWizard: cannot connect to network");
}

关于Android连接到EAP-AKA WiFi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36187962/

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