Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating WPA2 PSK Access Point in Android Programmatically

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

How can i do that? Regards

like image 297
Usman Riaz Avatar asked Jun 12 '26 10:06

Usman Riaz


1 Answers

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.

like image 95
Vivek Sasidharan Avatar answered Jun 14 '26 23:06

Vivek Sasidharan