哪一个是在Android下连接Wifi的最佳做法?

时间:2014-07-19 06:12:36

标签: java android networking wifi connectivity

这是关于网络Wifi如何在android下连接它。 但问题是哪一个是the Code shown at here.

之间的最佳做法

而且......下面这个? 因为给出的两个源代码具有相似性,但它们在配置内容方面有所不同。请发表评论/明确答复。

由于

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();

    }

0 个答案:

没有答案