Android: extracting wifi capabilities with contains

≡放荡痞女 提交于 2019-11-28 02:00:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!