2016-03-23 3 views
0

Ich brauche einen einfachen Code, wie man von der mobilen Anwendung auf sichere WIFI (EAP-AKA) verbinden. Ich habe unten Code, aber ich weiß nicht, ist oder richtig oder nicht und weiß nicht, wie man es benutzt. Es wird großartig sein, wenn jemand Beispielcode hat.Android verbinden mit EAP-AKA WiFi

// 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; 

Antwort

1

fand ich die Antwort, und beschlossen, es zu setzen, kann es jemand helfen werden

Beispielcode-Anwendung kann in meinem Repository https://github.com/malah-code/Android-Eap-Aka-Sample

-Code

// 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"); 
     } 
finden