Android Utililty Methods Mac Address Get

List of utility methods to do Mac Address Get

Description

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

Method

StringgetMac(Context context)
Obtain the mac address
WifiManager wifiManager = (WifiManager) context
        .getSystemService(Context.WIFI_SERVICE);
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
            .list(NetworkInterface.getNetworkInterfaces());
    for (NetworkInterface intf : interfaces) {
        if (interfaceName != null) {
            if (!intf.getName().equalsIgnoreCase(interfaceName))
                continue;
        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 "";