3

Is there a way to get wifi encryption type (like WSA, WSA2, WEP) programmatically on Android 6.0+ without using:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();

because I don't want to have to ask user for access to location.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

which appears to be a requirement when scanning wifi networks.

I am hoping there is a way to get this without having to scan all wifi networks like in the android.net.wifi.WifiInfo class.

Farhad
  • 12,178
  • 5
  • 32
  • 60
Veener
  • 4,771
  • 2
  • 29
  • 37

1 Answers1

3

NO, this is not possible. The only way you have to get the encryption type of current running wifi is by using the android.net.wifi.WifiInfo or ScanResults using iterations.

You can use the below example to get encryption type of current running Wifi with ScanResult

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();

//get current connected SSID for comparison to ScanResult
WifiInfo wi = wifi.getConnectionInfo();
String currentSSID = wi.getSSID();

    if (networkList != null) {
        for (ScanResult network : networkList)
        {
           //check if current connected SSID
           if (currentSSID.equals(network.SSID)){
            //get capabilities of current connection
            String Capabilities =  network.capabilities;        
            Log.d (TAG, network.SSID + " capabilities : " + Capabilities);

            if (Capabilities.contains("WPA2")) {
               //do something
            }
            else if (Capabilities.contains("WPA")) {
               //do something
            }
            else if (Capabilities.contains("WEP")) {
               //do something
            }
           }
        }
    }

You can get the refferences from here: https://stackoverflow.com/a/28906046/4360419

Community
  • 1
  • 1
Arsal Imam
  • 2,882
  • 2
  • 24
  • 35