get Active SSID - Android android.net.wifi

Android examples for android.net.wifi:Wifi SSID

Description

get Active SSID

Demo Code

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

public class Main{

    private static WifiManager mWifiManager;
    public static String getActiveSSID() {
        if (isWifiConnected()) {
            WifiInfo info = mWifiManager.getConnectionInfo();
            String ssid = info.getSSID();
            return ssid;
        } else {//from  w  w w  .j a v  a2 s.  c  o m
            return null;
        }
    }
    public static boolean isWifiConnected() {
        int state = mWifiManager.getWifiState();
        if (state != WifiManager.WIFI_STATE_ENABLED) {
            return false;
        }
        WifiInfo info = mWifiManager.getConnectionInfo();
        if (info.getIpAddress() != 0) {
            return true;
        } else {
            return false;
        }
    }

}

Related Tutorials