I want to create Access Point in android programmatically with the following configurations.
AccessPointName :SomeName
Security:WPA2 PSK
Password
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);
And finally pass this wifiConfiguration
using accesspoint as follows
WifiApControl apControl = WifiApControl.getInstance(context);
apControl.setEnabled(wifiConfiguration, true);
or else you can use this wifiConfiguration
with reflection techniques in java to activate the access point.