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 getMacInfo(Context context) {
    String macAddress = null, ip = null;
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
    if (null != info) {
        macAddress = info.getMacAddress();

    }//from w  ww  . j av a 2  s. c o m
    return macAddress;
}

From source file:Main.java

public static String pingGateWayInWifi(Context context) {
    String gateWay = null;/*w  w w  .j av a2  s  .  c o  m*/
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null) {
        return "wifiManager not found";
    }
    DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
    if (dhcpInfo != null) {
        int tmp = dhcpInfo.gateway;
        gateWay = String.format("%d.%d.%d.%d", (tmp & 0xff), (tmp >> 8 & 0xff), (tmp >> 16 & 0xff),
                (tmp >> 24 & 0xff));
    }
    return gateWay;
}

From source file:Main.java

public static String getMacAddress(Context context) {
    String mac = "";
    try {/*w w  w.  j ava  2  s  . c  o m*/
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        mac = info.getMacAddress();
        if (mac == null || mac.equalsIgnoreCase("null")) {
            mac = "";
        }
        return mac;
    } catch (Exception e) {
        return mac;
    }
}

From source file:Main.java

/**
 * @param context Context of application
 * @return    MAC address//from  www .  j a va 2 s.  c o m
 */
public static String getMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.getConnectionInfo().getMacAddress();
}

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 {/*from w  w w  .j a v  a2 s  .  c  o  m*/
        System.out.println("**** WIFI is off");
        return false;
    }
}

From source file:Main.java

public static void MulticastLockRelease(Context context) {
    if (multicastLock == null) {
        multicastLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
                .createMulticastLock("multicast.test");
    }//from w w w. j av  a 2s .  c  o  m
    multicastLock.release();
}

From source file:Main.java

public static int getLinkSpeedMax(Context context) {
    /**//from   w w w . ja v a2 s. c o m
     * Mbps
     */
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();
    Log.v("getLinkSpeed", String.valueOf(wi.getLinkSpeed()));
    return wi.getLinkSpeed();
}

From source file:Main.java

/**
 * Checks if wifi is ON//from   w w w  . ja  v a  2 s.c  o m
 * @param context
 * @return
 */
public static boolean isWifiOn(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifi.isWifiEnabled();
}

From source file:Main.java

/***
 * set wifi to on/off/*w  w w.j  a v  a 2s.co m*/
 * 
 * @param context
 * @param status
 */
public static void setWifi(Context context, boolean status) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(status);
}

From source file:Main.java

/**
 * set wifi is Enable/Disable./*from w  ww. ja va2  s.c o m*/
 * @param context
 * @param enable
 */
public static void setWifiEnable(Context context, boolean enable) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(enable);
}