Android 连接到 EAP-AKA WiFi
Android connect to EAP-AKA WiFi
我需要一个如何从移动应用程序连接到安全 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");
}
我需要一个如何从移动应用程序连接到安全 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");
}