Android: extracting wifi capabilities with contain

2020-02-11 13:02发布

I'm trying to know the type security of the scanned networks, and i'm getting result like this :

    [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]
    [WPA2-PSK-CCMP][WPS][ESS]

And i used this code :

 // Constants used for different security types
    public static final String WPA = "WPA";
    public static final String WEP = "WEP";
    public static final String WPA2 = "WPA2";
    public static final String OPEN = "Open";
final String cap = results.get(position).capabilities;
                final String[] securityModes = { WEP, WPA, WPA2 };
                for (int i = securityModes.length - 1; i >= 0; i--) {
                    if (cap.toLowerCase().contains(securityModes[i].toLowerCase())) {

                        textView5.setText(securityModes[i] );

                    }
                    else 
                        textView5.setText(OPEN );

                }

But i'm just obtaining in textViex :OPEN or WEP , i don't get WPA or WPA2, what could be the problem ?

1条回答
ら.Afraid
2楼-- · 2020-02-11 13:24

Try this function :

 public String security(String cap){


             if (cap.toLowerCase().contains(WEP.toLowerCase()))
             {return WEP ;}

             else if (cap.toLowerCase().contains(WPA2.toLowerCase()))
             {return WPA2;}

             else if (cap.toLowerCase().contains(WPA.toLowerCase()))
             {return WPA;}
             else 


            return OPEN;

        }
查看更多
登录 后发表回答