Ghost
Ghost

Reputation: 114

How to Detect Unsecured Wifi Android

WifiInfo class provides getCurrentSecurityType function but it is available only for API level 31 & above.

 private static void detectUnsecureWifiNetwork(Context context) {
        WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if (wifiManager.isWifiEnabled()) {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            if (wifiInfo != null) {
                Toast.makeText(context, "Wifi is enabled", Toast.LENGTH_SHORT).show();
    
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                    boolean isSecure = (wifiInfo.getCurrentSecurityType() != WifiInfo.SECURITY_TYPE_OPEN);
                    if (!isSecure) {
                        Toast.makeText(context, "Wifi is not secured", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(context, "Wifi is secured", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }
    }

I know other methods like scanning all the available netowork & then detect the security type but it requires LOCATION permission which I do not want to take from the user.

Is there any other way to detect unsecure network (wifi networks without password i.e. Security - NONE)? Any help will be appreciated.

Upvotes: 0

Views: 95

Answers (0)

Related Questions