Example usage for android.content Context WIFI_SERVICE

List of usage examples for android.content Context WIFI_SERVICE

Introduction

In this page you can find the example usage for android.content Context WIFI_SERVICE.

Prototype

String WIFI_SERVICE

To view the source code for android.content Context WIFI_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.

Usage

From source file:Main.java

public static String getMac(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    return info.getMacAddress();
}

From source file:Main.java

public static String getWifiMacAddress(Context mc) {
    WifiManager wifi = (WifiManager) mc.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    return info.getMacAddress();
}

From source file:Main.java

public static void setWifiEnabled(Context context, boolean enabled) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        wifiManager.setWifiEnabled(true);
    } else {//from  w w w .j  av a2s. co m
        wifiManager.setWifiEnabled(false);
    }
}

From source file:Main.java

public static String getLocalIp(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    int ip = info.getIpAddress();
    return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + (ip >> 24 & 0xFF);
}

From source file:Main.java

public static String getSSid(Context ctx) {
    WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    if (wm != null) {
        WifiInfo wi = wm.getConnectionInfo();
        if (wi != null) {
            String s = wi.getSSID();
            if (s.length() > 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
                return s.substring(1, s.length() - 1);
            }/*from w w  w .  j  a v a 2 s  . co  m*/
        }
    }
    return "";
}

From source file:Main.java

public static String getWifiAddress(Context c) {
    WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null) {
        return wifiInfo.getMacAddress();
    }/*from w w  w. ja v  a2  s  .c  om*/
    return "";
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wm.getConnectionInfo();
    return info.getMacAddress();

}

From source file:Main.java

public static boolean getWifiStatus(Context ctx) {
    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int state = wifiInfo.getNetworkId();
    return state != -1;
}

From source file:Main.java

public static boolean checkWIFI(Context cxt) {
    WifiManager wifi = (WifiManager) cxt.getSystemService(Context.WIFI_SERVICE);
    if ((wifi.isWifiEnabled() == true)) {

        WifiInfo wifiInf = wifi.getConnectionInfo();
        /* Get the MAC ADD of WIFI */
        // Commons.MAC_ID = wifiInf.getMacAddress();
        return true;
    } else {/*from w ww .  j  av a  2s. c  o m*/
        return false;

    }
}

From source file:Main.java

public static String getMac(Context context) {

    WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = manager.getConnectionInfo();
    String mac = info.getMacAddress();
    if (mac == null)
        mac = "";
    return mac;//from   ww w  .  j  av  a 2s .co m
}