gpt4 book ai didi

android - 有没有办法通过 EAP-TTLS 以编程方式连接到 Passpoint/Hotspot2.0 网络?

转载 作者:行者123 更新时间:2023-11-29 02:20:06 29 4
gpt4 key购买 nike

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

最佳答案

userCredential.setPassword(key) 中使用的 key 在设置为 userCredential 之前必须是 base 64 编码。

关于android - 有没有办法通过 EAP-TTLS 以编程方式连接到 Passpoint/Hotspot2.0 网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56798610/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com