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

private static String getImei(Context context) {
    String imei = "";
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    if (info != null) {
        imei = info.getMacAddress();/*from  w ww .  j a va  2s  .co  m*/
        if (imei != null) {
            return imei;
        }
    }
    return imei;
}

From source file:Main.java

public static String getMac(Context ctx) {

    String macAddress = "0";

    WifiManager wifi = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);

    WifiInfo info = wifi.getConnectionInfo();

    macAddress = info.getMacAddress();//from www.j  a v a  2 s . c  o  m

    return macAddress;

}

From source file:Main.java

public static MulticastLock openWifiBrocast(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    MulticastLock multicastLock = wifiManager.createMulticastLock("MediaRender");
    if (multicastLock != null) {
        multicastLock.acquire();/*from  w w  w  .  j  av  a 2s.  co m*/
    }
    return multicastLock;
}

From source file:Main.java

public static String getWifiIP(Context context) {
    String ip = null;/*from   w  w w. j  a va2s. com*/
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager.isWifiEnabled()) {
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int i = wifiInfo.getIpAddress();
        ip = (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + (i >> 24 & 0xFF);
    }
    return ip;
}

From source file:Main.java

public static boolean setWifi(Context context, boolean enable) throws Exception {
    if (isWifiOpen(context) != enable) {
        ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).setWifiEnabled(enable);
    }//from  www .  j a va2 s.c om

    return true;
}

From source file:Main.java

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

From source file:Main.java

public static String GetMacAddress(Context context) {
    String macAddress = null;//from   ww  w . j a va  2s .c  o m
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
    if (info != null) {
        macAddress = info.getMacAddress();
    }
    return macAddress;
}

From source file:Main.java

public static String getBroadcastAddress(Context ctx) {
    WifiManager cm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo myDhcpInfo = cm.getDhcpInfo();
    if (myDhcpInfo == null) {
        return "255.255.255.255";
    }/*from  w  w  w . jav  a2s .c  om*/
    int broadcast = (myDhcpInfo.ipAddress & myDhcpInfo.netmask) | ~myDhcpInfo.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    try {
        return InetAddress.getByAddress(quads).getHostAddress();
    } catch (Exception e) {
        return "255.255.255.255";
    }
}

From source file:Main.java

public static String getLocalMacAddress(Context ctx) {

    String macAddress = "0";

    WifiManager wifi = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);

    WifiInfo info = wifi.getConnectionInfo();

    macAddress = info.getMacAddress().replaceAll(":", "");

    return macAddress;

}

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();
}