我正在尝试在Android应用程序中创建WifiConfiguration对象或PasspointConfiguration对象,该对象将使我能够在启用后将设备连接到Passpoint网络。
我尝试通过建立WifiConfiguration对象并将其添加到WifiManager,然后启用它来进行连接。
我也尝试过构建PasspointConfiguration对象,但是当我尝试使用PasspointConfiguration对象运行WifiManager.addOrUpdatePasspointConfiguration()时,应用程序崩溃并抛出IllegalArgumentException。我假设这是无效的配置问题。
// WifiConfiguration/WifiEnterpriseConfiguration approach
WifiConfiguration wc = new WifiConfiguration();
wc.status = WifiConfiguration.Status.ENABLED;
wc.isHomeProviderNetwork = true;
wc.FQDN = this.domain;
wifiEnterpriseConfig.setIdentity(user);
wifiEnterpriseConfig.setPassword(key);
wifiEnterpriseConfig.setAnonymousIdentity(this.outerID);
wifiEnterpriseConfig.setRealm(this.realm);
wifiEnterpriseConfig.setDomainSuffixMatch(this.domain);
wifiEnterpriseConfig.setEapMethod(this.eapMethod);
wifiEnterpriseConfig.setPhase2Method(this.phase2Auth);
wifiEnterpriseConfig.setCaCertificate(this.cert);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
wc.enterpriseConfig = wifiEnterpriseConfig;
wifiManager.disconnect();
this.networkID = wifiManager.addNetwork(wc);
wifiManager.enableNetwork(this.networkID, true);
// PasspointConfiguration approach
Credential.UserCredential userCredential = new Credential.UserCredential();
userCredential.setEapType(21);
userCredential.setPassword(key);
userCredential.setUsername(user);
userCredential.setNonEapInnerMethod("MS-CHAP-V2");
Credential credential = new Credential();
credential.setRealm(this.realm);
credential.setUserCredential(userCredential);
credential.setCertCredential(null);
credential.setCaCertificate(null);
credential.setClientPrivateKey(null);
credential.setClientCertificateChain(null);
HomeSp homeSp = new HomeSp();
homeSp.setFqdn(this.domain);
homeSp.setFriendlyName(this.friendlyName);
PasspointConfiguration passpointConfiguration = new PasspointConfiguration();
passpointConfiguration.setCredential(credential);
passpointConfiguration.setHomeSp(homeSp);
wifiManager.addOrUpdatePasspointConfiguration(passpointConfiguration);
我希望在将其中一种配置添加到WifiManager后,应用程序将设备连接到Passpoint / Hotspot2.0网络。
第一种方法不会产生错误,但是不会将应用程序连接到网络。
以下是PasspointConfiguration IllegalArgumentException的堆栈跟踪:
Process: com.***.***.***, PID: 4101
java.lang.IllegalArgumentException
at android.net.wifi.WifiManager.addOrUpdatePasspointConfiguration(WifiManager.java:1483)
at com.***.***.***.models.<PrivateClass>.<PrivateMethod1>(<PrivateClass>.java:197)
at com.***.***.***.models.<PrivateClass>.<PrivateMethod2>(<PrivateClass>.java:219)
at com.***.***.***.models.<PrivateClass>.<PrivateMethod3>(<PrivateClass>.java:116)
at com.***.***.***.UserView.<PrivateMethod4>(UserView.java:178)
at com.***.***.***.UserView.access$100(UserView.java:34)
at com.***.***.***.UserView$2.onClick(UserView.java:200)
at android.view.View.performClick(View.java:7327)
at android.widget.TextView.performClick(TextView.java:14160)
at android.view.View.performClickInternal(View.java:7299)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27774)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
答案 0 :(得分:3)
userCredential.setPassword(key)中使用的密钥必须设置为base 64编码,然后才能设置为userCredential。
答案 1 :(得分:0)
credential.setCaCertificate(null); 密码不能像今天一样为空。
答案 2 :(得分:0)
addOrUpdatePasspointConfiguration已在Android 11中删除。 您可以使用WifiNetworkSuggestion在Android 11上执行此操作吗?