PasspointConfiguration

PasspointConfiguration

我试图在我的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)

最佳答案

credential.setCaCertificate(null);
对于通行证,不能像今天一样为null。

10-04 13:13