|
@@ -328,6 +328,34 @@ public class NetHelper {
|
|
return mac;
|
|
return mac;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public String getMacAddress2() {
|
|
|
|
+ List<NetworkInterface> interfaces = 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";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 通过WiFiManager获取mac地址
|
|
* 通过WiFiManager获取mac地址
|
|
* 这个方法Android 7.0是获取不到的,返回的是null,其实是返回“02:00:00:00:00:00”
|
|
* 这个方法Android 7.0是获取不到的,返回的是null,其实是返回“02:00:00:00:00:00”
|