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 getLocalMacAddress1(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    if (info != null) {
        return info.getMacAddress();
    }/* w w w  .j  ava  2s .  c o  m*/
    return null;
}

From source file:Main.java

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

From source file:Main.java

public static int getIpAddressInt(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null)
        return 0;
    WifiInfo info = wifiManager.getConnectionInfo();
    return info == null ? 0 : info.getIpAddress();
}

From source file:Main.java

public static void changeWifiState(Activity activitiy, boolean isOn) {
    WifiManager wm = (WifiManager) activitiy.getSystemService(Context.WIFI_SERVICE);
    if (null != wm) {
        wm.setWifiEnabled(isOn);/*from ww w  .  jav  a  2 s  . c o m*/
    }
}

From source file:Main.java

public static boolean isWiFiActive(Context context) {
    WifiManager wm = null;//ww w .j av a2s .co  m
    try {
        wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (wm == null || wm.isWifiEnabled() == false)
        return false;

    return true;
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo.getMacAddress() != null) {
        return wifiInfo.getMacAddress();
    } else {//from  w w w . j  av a 2  s.  c o  m
        return "";
    }
}

From source file:Main.java

public static String getWifiIp(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    boolean enable = wifiManager.isWifiEnabled();
    if (!enable) {
        return null;
    }//from   www.j  a v a2 s  .c  o m
    WifiInfo wifiinfo = wifiManager.getConnectionInfo();
    return intToIp(wifiinfo.getIpAddress());
}

From source file:Main.java

public static boolean isWiFiActive(Context inContext) {
    WifiManager wm = null;/*  ww w. j  a  v  a2  s .c o m*/
    try {
        wm = (WifiManager) inContext.getSystemService(Context.WIFI_SERVICE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (wm == null || wm.isWifiEnabled() == false)
        return false;
    return true;
}

From source file:Main.java

public static String getWIFIIP(Context context) {
    WifiManager wifimanage = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    if (!wifimanage.isWifiEnabled()) {
        wifimanage.setWifiEnabled(true);
    }/*from w  w  w  . ja v  a  2  s  . c  o m*/

    WifiInfo wifiinfo = wifimanage.getConnectionInfo();

    String ip = intToIp(wifiinfo.getIpAddress());
    return ip;
}

From source file:Main.java

public static String getDevicesIP(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*from ww w  . j a  v a 2  s.com*/
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();
    String ip = (ipAddress & 0xFF) + "." + ((ipAddress >> 8) & 0xFF) + "." + ((ipAddress >> 16) & 0xFF) + "."
            + (ipAddress >> 24 & 0xFF);
    if (ip == null || ip.equals("0.0.0.0")) {

    }
    return ip;
}