12

最近 Android 添加了使用 API 18 (JellyBean 4.3) 连接到 EAP WIFI 的功能。我已经寻找了许多示例,但找不到任何示例,并且我无法连接我的代码。一切似乎都按预期工作,但实际连接似乎不起作用。

这是我正在做的事情:

Log.d( "WiFi", "adding network via Android Enterprise Config with SSID: " + ssid );
                    WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); 
                    wifiConfig = new WifiConfiguration();
                    wifiConfig.SSID = ssid; 

                    enterpriseConfig.setIdentity(userName);
                    enterpriseConfig.setPassword(passWord);
                    enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PEAP); 
                    wifiConfig.enterpriseConfig = enterpriseConfig;
                    Log.i("WIFI", "My wifi"+ wifiConfig.status); 
                    networkId = wfm.addNetwork(wifiConfig);

                    wfm.enableNetwork(networkId, true); // this initiates the connection

无论出于何种原因,都没有建立连接。看来其他所有设置都正确。如果我遗漏了任何内容,请告诉我,我会很乐意添加它。

任何帮助或方向将不胜感激。

4

1 回答 1

21

您需要设置密钥管理

   WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); 
   wifiConfig = new WifiConfiguration();
   wifiConfig.SSID = ssid; 
   wifiConfig.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
   wifiConfig.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
   enterpriseConfig.setIdentity(userName);
   enterpriseConfig.setPassword(passWord);
   enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PEAP); 
   wifiConfig.enterpriseConfig = enterpriseConfig;
于 2013-10-07T23:29:41.343 回答