Android: extracting wifi capabilities with contains
Asked Answered
M

1

2

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 ?

Montagnard answered 13/5, 2014 at 17:2 Comment(0)
M
3

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;

        }
Montagnard answered 14/5, 2014 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.