0

I have created an wifiap with a password, but for a project I would like to create a open network. I have tried the following, but if there already is a password, then it is still active.

        Method getWifiConfig = mWifiManager.getClass().getMethod("getWifiApConfiguration",null);
        WifiConfiguration wifiConf  = (WifiConfiguration)getWifiConfig.invoke(mWifiManager, null); 
        wifiConf.SSID = "enny";
        //wifiConf.preSharedKey = "fuunnv12345";

        wifiConf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
        wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
        wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        Method setWifiConfig = mWifiManager.getClass().getMethod("setWifiApConfiguration",WifiConfiguration.class);
        setWifiConfig.invoke(mWifiManager,wifiConf);
        Method method = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
        method.invoke(mWifiManager, null, enabled);
jonesw
  • 51
  • 1
  • 8
  • Try removing these two lines `wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.WPA);` One more thing to try is disable softAP `setWifiApEnabled(null, false)` and reenable with updated config `setWifiApEnabled(WifiConfig, true);` – vishalm Jan 27 '14 at 16:39
  • I tried this, but in my case it didn't help. – jonesw Jan 29 '14 at 20:47

1 Answers1

0

I found a solution. Inspired by this answer, How to programmatically create and read WEP/EAP WiFi configurations in Android?, I got information from the wificonfiguration in the wifiAP. This showed which fields were set to true when configuring a wifiAP by using the normal setup provided in Android. So when I want to change a wifiAP from a locked to an open I set these keys to false. For my case I set the following parameters:

wifiConf.preSharedKey = null;
wifiConf.allowedKeyManagement.set(KeyMgmt.NONE); 
wifiConf.allowedKeyManagement.set(KeyMgmt.WPA2_PSK,false);
wifiConf.allowedKeyManagement.set(KeyMgmt.WPA_PSK,false);
Community
  • 1
  • 1
jonesw
  • 51
  • 1
  • 8