Код: Выделить всё
val all = Collections.list(NetworkInterface.getNetworkInterfaces())
for (nif in all) {
if (nif.name.contains("wlan") || nif.name.contains("eth")) {
val macBytes = nif.hardwareAddress ?: return ""
val res1 = StringBuilder()
for (b in macBytes) {
res1.append(String.format("%02X:", b))
}
if (res1.length > 0) {
res1.deleteCharAt(res1.length - 1)
}
return res1.toString().toUpperCase()
}
}
но в коде Java (то же устройство)
Код: Выделить всё
List all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (nif.getName().contains("wlan") || nif.getName().contains("eth")) {
byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
}
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:", b));
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
mac = res1.toString().toUpperCase();
}
}
Оба приложения имеют разрешения
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/685 ... e-wlan0-in