Example usage for android.net.wifi WifiManager getConnectionInfo

List of usage examples for android.net.wifi WifiManager getConnectionInfo

Introduction

In this page you can find the example usage for android.net.wifi WifiManager getConnectionInfo.

Prototype

public WifiInfo getConnectionInfo() 

Source Link

Document

Return dynamic information about the current Wi-Fi connection, if any is active.

Usage

From source file:Main.java

public static String getWifiMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager != null && wifiManager.getConnectionInfo() != null) {
        return wifiManager.getConnectionInfo().getMacAddress();
    }/* www  . java  2 s. c o  m*/

    return null;
}

From source file:Main.java

static public String get_wifi_ssid(Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    final WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    return wifiInfo.getSSID();
}

From source file:Main.java

public static String getMac(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    if (info.getMacAddress() == null) {
        return null;
    } else {//from w w w  .  j  a  v  a  2s  . co m
        return info.getMacAddress();
    }
}

From source file:Main.java

@SuppressWarnings("MissingPermission")
public static String getWifiMacAddr(Context ctx) {
    String macAddr = "";
    try {/*from  ww  w  . j a  va 2s  .co m*/
        WifiManager wifi = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
        macAddr = wifi.getConnectionInfo().getMacAddress();
        if (macAddr == null) {
            macAddr = "";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return macAddr;
}

From source file:Main.java

public static String getSSID(Context context) {

    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    if (info.getSSID() == null) {
        return null;
    } else {/*w  w  w. ja  v  a2  s.co m*/
        return info.getSSID();
    }
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String macAddress = info.getMacAddress().replace(":", "");
    return macAddress == null ? "" : macAddress;
}

From source file:Main.java

public static String getMacAddress(Context context) {
    if (TextUtils.isEmpty(macAddress)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        if (wifiInfo != null) {
            macAddress = wifiInfo.getMacAddress();
            return macAddress;
        }//  w  w  w. j a va2  s. c  o m
    }
    return macAddress;
}

From source file:Main.java

public static boolean isWiFiActive(Context inContext) {
    WifiManager mWifiManager = (WifiManager) inContext.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    int ipAddress = wifiInfo == null ? 0 : wifiInfo.getIpAddress();
    if (mWifiManager.isWifiEnabled() && ipAddress != 0) {
        System.out.println("**** WIFI is on");
        return true;
    } else {/*  w  w  w.j  av a 2  s  .  co m*/
        System.out.println("**** WIFI is off");
        return false;
    }
}

From source file:Main.java

public static WifiInfo getWifiConnectionInfo(Context context) {
    WifiManager mainWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ;//from   w w  w. ja  v a 2  s  . co  m
    WifiInfo wifiInfo = mainWifi.getConnectionInfo();
    return wifiInfo;
}

From source file:Main.java

final public static String getWifiSsidName(WifiManager wm) {
    String wssid = "";
    if (wm.isWifiEnabled()) {
        String tssid = wm.getConnectionInfo().getSSID();
        if (tssid == null || tssid.equals("<unknown ssid>"))
            wssid = "";
        else//from  w  ww.j  a  v  a2 s .  c om
            wssid = tssid.replaceAll("\"", "");
        if (wssid.equals("0x"))
            wssid = "";
    }
    return wssid;
}