在Android中以编程方式创建WPA2 PSK接入点 [英] Creating WPA2 PSK Access Point in Android Programmatically

查看:170
本文介绍了在Android中以编程方式创建WPA2 PSK接入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下配置以编程方式在android中创建访问点. AccessPointName :SomeName Security:WPA2 PSK Password:SomeKey

I want to create Access Point in android programmatically with the following configurations. AccessPointName :SomeName Security:WPA2 PSK Password:SomeKey

我该怎么做? 问候

推荐答案

我曾经遇到过这个问题.为了创建WPA2 PSK访问点,您需要使用WPA2 PSK参数填充WifiConfiguartion对象.但是我找不到将KeyManagement设置为WPA2_PSK的方法.只有WPA_PSKIEEE8021XWPA_EAPNONE的选项.然后,我阅读了 WifiConfiguration.java .我能够发现确实存在WPA2_PSK的选项,但是它被@hide隐藏,但是它是一个值为4int.所以我要做的是在wifiConfiguration.allowedKeyManagement.set(4);中传递4.参见下面的代码.

I had faced this problem once. In order to create a WPA2 PSK access point, you need to populate the WifiConfiguartion object with your WPA2 PSK parameters. However I could not find a way to set KeyManagement as WPA2_PSK. There was only options for WPA_PSK, IEEE8021X, WPA_EAP and NONE. Then I read the android source code for WifiConfiguration.java. I was able to find out that indeed there is option for WPA2_PSK, but it is hidden by @hide, but it is an int with value 4. So what I did was to pass 4 in wifiConfiguration.allowedKeyManagement.set(4);. See code below.

WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "SomeName";
wifiConfiguration.preSharedKey = "SomeKey";
wifiConfiguration.hiddenSSID = false;
wifiConfiguration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedKeyManagement.set(4);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

最后使用访问点如下传递该wifiConfiguration

WifiApControl apControl = WifiApControl.getInstance(context);

apControl.setEnabled(wifiConfiguration, true);

,否则您可以将此wifiConfiguration与Java中的反射技术一起使用以激活访问点.

or else you can use this wifiConfiguration with reflection techniques in java to activate the access point.

这篇关于在Android中以编程方式创建WPA2 PSK接入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆