标签:
String networkTypeString = theWifiResult.getNetworkEncryption(); NetworkType networkType; try { networkType = NetworkType.forIntentValue(networkTypeString); } catch (IllegalArgumentException ignored) { Log.w(TAG, "Bad network type; see NetworkType values: " + networkTypeString); return null; } if (networkType == NetworkType.NO_PASSWORD) { changeNetworkUnEncrypted(wifiManager, theWifiResult); } else { String password = theWifiResult.getPassword(); if (password != null && !password.isEmpty()) { if (networkType == NetworkType.WEP) { changeNetworkWEP(wifiManager, theWifiResult); } else if (networkType == NetworkType.WPA) { changeNetworkWPA(wifiManager, theWifiResult); } } }
theWifiResult.getNetworkEncryption(); 就是得到wifi的类型的,这个方法的获取是通过核心包Core中WifiResultParser的parser解析后返回WifiParsedResult类中包含的
public WifiParsedResult parse(Result result) { String rawText = getMassagedText(result); if (!rawText.startsWith("WIFI:")) { return null; } String ssid = matchSinglePrefixedField("S:", rawText, ‘;‘, false); if (ssid == null || ssid.isEmpty()) { return null; } String pass = matchSinglePrefixedField("P:", rawText, ‘;‘, false); String type = matchSinglePrefixedField("T:", rawText, ‘;‘, false); if (type == null) { type = "nopass"; } boolean hidden = Boolean.parseBoolean(matchSinglePrefixedField("H:", rawText, ‘;‘, false)); return new WifiParsedResult(type, ssid, pass, hidden); }
标签:
原文地址:http://www.cnblogs.com/zhangjin055/p/4699682.html