问题
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:
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;
}
来源:https://stackoverflow.com/questions/23637433/android-extracting-wifi-capabilities-with-contains