开发者

Android: How to get current Wifi encryption?

I have a listener listening for connectivity changes, especially from GSM to WIFI. Now I would like to log which WIFIs 开发者_运维技巧the user connects to, especially the encryption type (none, WEP, WPA, WPA2, ...) of the WIFI.

The listener works perfectly, but I can't find any way to get the current Wifi's encryption type.

Thanks for your help.


Use WifiManager to obtain details of the current connection, and then obtain a WifiConfiguration which should give you further information.

WifiManager wifiManager= (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wi = WifiManager.getConnectionInfo();
if( wi != null )
{
    WifiConfiguration activeConfig = null;
    for( WifiConfiguration conn : wifiManager.getConfiguredNetworks() )
    {
        if( conn.status == WifiConfiguration.Status.CURRENT )
        {
            activeConfig = conn;
            break;
        }
    }
    if( activeConfig != null )
    {
        // Analyse encryption of connected network here.
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜