connect wpa2 enterprise wifi connection programmatically in android

你。 提交于 2019-12-04 11:23:12

I have solved it by the help of this link

  WifiConfiguration config = new WifiConfiguration();
    config.SSID = "\"" + networkSSID + "\"";
    config.BSSID = Bssid;
    config.priority = 1;
 String networkIdentity = "";
         networkPasskey = "";
        config.status = WifiConfiguration.Status.ENABLED;
        WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
        enterpriseConfig.setIdentity(networkIdentity);
        enterpriseConfig.setPassword(networkPasskey);
        enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PEAP);
        enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);
        config.enterpriseConfig = enterpriseConfig;
   WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    int id = myWifiManager.addNetwork(config);
    Log.d("addNetwork", "# addNetwork returned " + id);

    myWifiManager.enableNetwork(id, true);

but this method will work till android 7.0 in android 8.0 they have restricted many function we can not add wifi configuration manually.

three things we must know when you are trying to configure with wpa2 enterprise

  1. you must know the EAP method it can be anything but mostly they will use PEAP

2.you must know about the Phase2 method, mostly they will use MSCHAPV2

  1. Certificate this one maximum Do Not validate.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!