public String getMacAddress() {
Listinterfaces = null;
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null && macBytes.length > 0) {
StringBuilder str = new StringBuilder();
for (byte b : macBytes) {
str.append(String.format("%02X:", b));
}
if (str.length() > 0) {
str.deleteCharAt(str.length() - 1);
}
return str.toString();
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "unknown";
}