Example usage for android.net.wifi WifiInfo getMacAddress

List of usage examples for android.net.wifi WifiInfo getMacAddress

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo getMacAddress.

Prototype

public String getMacAddress() 

Source Link

Usage

From source file:Main.java

public static String getWifiMac(Context context) {
    try {/*from w  w w . ja v a2 s .  c  om*/
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        return info.getMacAddress();
    } catch (Exception e) {
        return "x";
    }
}

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 w w  w  .  j  av a 2s  .  c  o m
}

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 a va 2  s .com
        return "";
    }
}

From source file:Main.java

public static String getMacAddress(Context context) {
    try {//w w w.j  a va  2  s.co  m
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        String mac = info.getMacAddress();
        return mac == null ? "" : mac;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static String getWifiMac1(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifi != null) {
        WifiInfo info = wifi.getConnectionInfo();
        String mac = info.getMacAddress();
        return mac;
    }/*w  w w  .jav  a 2 s .  c  o m*/

    return "";
}

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  ww  w.j a v  a2  s .  c o m*/
        return info.getMacAddress();
    }
}

From source file:Main.java

public static String getMacAddress(Context context) {
    String mac = "";
    try {//from   w  w w  .  j  av  a  2s . co  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

public static String getDevicesMac(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*from  w  ww.j a  va  2s. c  o m*/
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String mac = wifiInfo.getMacAddress().toString();
    return mac;
}

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

public static String getMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifiManager.getConnectionInfo();
    String macAddress = wInfo.getMacAddress();
    return macAddress;
}