Android obtains the currently hidden and unhidden wifi encryption methods (Security)
1. General WIFI encryption there are several ways: (1). WPA-PSK/WPA2-PSK (currently the most secure household encryption)
(2). WPA/WPA2 (relatively insecure)
(3). WEP (poor security)
2. Generally, details will pop up when you click on the current network of the system.
How can we obtain this security? You can see from the system source code:
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); WifiManager mWifiManager = (WifiManager) getSystemService (Context. WIFI_SERVICE); WifiInfo = mWifiManager. getConnectionInfo (); // get the configured network connection List
WifiConfigList = mWifiManager. getConfiguredNetworks (); for (int I = 0; I <wifiConfigList. size (); I ++) {Log. I ("hefeng", wifiConfigList. get (I ). toString (); Log. I ("hefeng", info. getSSID () + "|" + wifiConfigList. get (I ). SSID); if (info. getSSID (). equals (wifiConfigList. get (I ). SSID) {Log. e ("hefeng", "Current Network Security:" + getSecurity (wifiConfigList. get (I) ;}}/ *** These values are matched in string arrays -- Changes must be kept in sync */static final int SECURITY_NONE = 0; static final int SECURITY_WEP = 1; static final int SECURITY_PSK = 2; static final int SECURITY_EAP = 3; static int getSecurity (WifiConfiguration config) {if (config. allowedKeyManagement. get (KeyMgmt. WPA_PSK) {return SECURITY_PSK;} if (config. allowedKeyManagement. get (KeyMgmt. WPA_EAP) | config. allowedKeyManagement. get (KeyMg Mt. IEEE8021X) {return SECURITY_EAP;} return (config. wepKeys [0]! = Null )? SECURITY_WEP: SECURITY_NONE ;}
In this way, we can get the result. In this way, you can avoid hiding your Wi-Fi ssid and obtain the encryption method 3. the general encryption method is as follows, but once you set the ssid on the vro to hide it, you cannot find it.
public void getCipherType(Context context, String ssid) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); List
list = wifiManager.getScanResults(); for (ScanResult scResult : list) { if (!TextUtils.isEmpty(scResult.SSID) && scResult.SSID.equals(ssid)) { String capabilities = scResult.capabilities; Log.i("hefeng","capabilities=" + capabilities); if (!TextUtils.isEmpty(capabilities)) { if (capabilities.contains("WPA") || capabilities.contains("wpa")) { Log.i("hefeng", "wpa"); } else if (capabilities.contains("WEP") || capabilities.contains("wep")) { Log.i("hefeng", "wep"); } else { Log.i("hefeng", "no"); } } } } }