Which one is the best practice to connect Wifi under Android?

帅比萌擦擦* 提交于 2019-12-24 11:34:20

问题


This is about network Wifi how to connect it under android. But the question is which one is the best practice between the Code shown at here.

And... this below? Because two of the source code given have a similarity but they're different in configuring the content. Please give a comment / clear answer.

Thanks

private void getConnected(){

        // for Wifi Connectivity
        obWifiManager = (WifiManager) getApplicationContext().getSystemService(
                Context.WIFI_SERVICE);

        WifiConfiguration config = new WifiConfiguration();
        config.SSID = "\""+objOpp.getName()+"\"";
        config.BSSID = objOpp.getID();
        config.priority = 1;
        config.preSharedKey = "\""+ "PASSWORD"+"\"";
        config.status = WifiConfiguration.Status.DISABLED;
        config.status = WifiConfiguration.Status.CURRENT; config.status = WifiConfiguration.Status.ENABLED;
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.NONE);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
        config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
        config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
        config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.LEAP);
        config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
        config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);

        obWifiManager.addNetwork(config);

        // start connection 
        obWifiManager.enableNetwork(config.networkId, true);
        obWifiManager.saveConfiguration();

    }

来源:https://stackoverflow.com/questions/24837337/which-one-is-the-best-practice-to-connect-wifi-under-android

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