Creating WPA2 PSK Access Point in Android Programmatically

后端 未结 4 1316
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 16:09

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 16:49

    I was also facing same problem by passing 4 as KeyMangement solved my problem.

    WifiConfiguration myConfig = new WifiConfiguration();
            myConfig.SSID = ssid; // SSID name of netwok
            myConfig.preSharedKey = password; // password for network
            myConfig.allowedKeyManagement.set(4); // 4 is for KeyMgmt.WPA2_PSK which is not exposed by android KeyMgmt class
            myConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); // Set Auth Algorithms to open
            try {
                Method method = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
                return (Boolean) method.invoke(mWifiManager, myConfig, true);  // setting and turing on android wifiap with new configrations
            } catch (Exception e) {
                e.printStackTrace();
            }
    

    Read more at Link

提交回复
热议问题