Android Utililty Methods Mac Address Get

List of utility methods to do Mac Address Get


The list of methods to do Mac Address Get are organized into topic(s).


StringgetMac(Context context)
Obtain the mac address
WifiManager wifiManager = (WifiManager) context
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String macAddress = wifiInfo.getMacAddress();
return macAddress;
StringgetMACAddress(String interfaceName)
Returns MAC address of the given interface name.
try {
    List<NetworkInterface> interfaces = Collections
    for (NetworkInterface intf : interfaces) {
        if (interfaceName != null) {
            if (!intf.getName().equalsIgnoreCase(interfaceName))
        byte[] mac = intf.getHardwareAddress();
        if (mac == null)
            return "";
        StringBuilder buf = new StringBuilder();
        for (int idx = 0; idx < mac.length; idx++)
            buf.append(String.format("%02X:", mac[idx]));
        if (buf.length() > 0)
            buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
} catch (Exception ex) {
return "";