Android: How to create EAP wifi configuration programmatically?

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

I know how to create Open/WEP/PSK/PSK2 configuration programmatically.

ex.

WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "ssid"; conf.preSharedKey = "\"password\""; conf.status = WifiConfiguration.Status.ENABLED;          conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);  conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);  conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);  conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);  conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);  conf.allowedProtocols.set(WifiConfiguration.Protocol.WPA); conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);  int res = wifi.addNetwork(conf); boolean b = wifi.enableNetwork(res, true); 

But how do I create one for '802.1x EAP'? Looking into the source code at: ..\packages\apps\Settings\src\com\android\settings\wifi\WifiDialog.java

case AccessPoint.SECURITY_EAP:                 config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);                 config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);                 config.eap.setValue((String) mEapMethod.getSelectedItem());                  config.phase2.setValue((mPhase2.getSelectedItemPosition() == 0) ? "" :                         "auth=" + mPhase2.getSelectedItem());                 config.ca_cert.setValue((mEapCaCert.getSelectedItemPosition() == 0) ? "" :                         KEYSTORE_SPACE + Credentials.CA_CERTIFICATE +                         (String) mEapCaCert.getSelectedItem());                 config.client_cert.setValue((mEapUserCert.getSelectedItemPosition() == 0) ? "" :                         KEYSTORE_SPACE + Credentials.USER_CERTIFICATE +                         (String) mEapUserCert.getSelectedItem());                 config.private_key.setValue((mEapUserCert.getSelectedItemPosition() == 0) ? "" :                         KEYSTORE_SPACE + Credentials.USER_PRIVATE_KEY +                         (String) mEapUserCert.getSelectedItem());                 config.identity.setValue((mEapIdentity.length() == 0) ? "" :                         mEapIdentity.getText().toString());                 config.anonymous_identity.setValue((mEapAnonymous.length() == 0) ? "" :                         mEapAnonymous.getText().toString());                 if (mPassword.length() != 0) {                     config.password.setValue(mPassword.getText().toString());                 } 

Seems to do the work but 'config.eap' is not accessable from my application.

Is there a way to configure EAP types or is it not possible?

回答1:

I answered this here: How to programmatically create and read WEP/EAP WiFi configurations in Android?

hth :)



回答2:

not sure if this helps, but it would be cool is you could configure 802.1X/EAP/enterprise via QR code:

http://code.google.com/p/zxing/issues/detail?id=589&colspec=ID%20Type%20Status%20Priority%20Owner%20Summary



回答3:

Java Reflection API can be used to create IEEE802.x network with certificate. You can directily create IEEE802.x network connection is earlier version (like 1.6). In latest android the "EnterpriseField" (a inner class) is not directily accessible through program.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!