|
|
@@ -17,6 +17,9 @@ import org.cocos2dx.javascript.thirdSdk.oaid.OaidHelper;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.LineNumberReader;
|
|
|
+import java.net.NetworkInterface;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class DeviceUtil {
|
|
|
|
|
|
@@ -99,14 +102,18 @@ public class DeviceUtil {
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
Log.e("=====", "7.0以上");
|
|
|
strMac = getMac();
|
|
|
+ Log.e("=====",Build.VERSION.SDK_INT +"");
|
|
|
+ Log.e("=====",strMac);
|
|
|
+ String strMac1= getNewMac();
|
|
|
+ Log.e("=====",strMac1);
|
|
|
return strMac;
|
|
|
}
|
|
|
return "02:00:00:00:00:00";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 这是使用adb shell命令来获取mac地址的方式
|
|
|
- *
|
|
|
+ * 这是使用adb shell命令来获取mac地址的方式(可获取7.0以上 亲测)
|
|
|
+ * @description
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getMac() {
|
|
|
@@ -141,7 +148,6 @@ public class DeviceUtil {
|
|
|
|
|
|
/**
|
|
|
* 根据wifi信息获取本地mac
|
|
|
- *
|
|
|
* @param context
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -160,6 +166,37 @@ public class DeviceUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 通过网络接口取 (7.0以上可用 亲测)(暂时不用)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String getNewMac() {
|
|
|
+ try {
|
|
|
+ List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
|
|
|
+ for (NetworkInterface nif : all) {
|
|
|
+ if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
|
|
|
+
|
|
|
+ byte[] macBytes = nif.getHardwareAddress();
|
|
|
+ if (macBytes == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder res1 = new StringBuilder();
|
|
|
+ for (byte b : macBytes) {
|
|
|
+ res1.append(String.format("%02X:", b));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res1.length() > 0) {
|
|
|
+ res1.deleteCharAt(res1.length() - 1);
|
|
|
+ }
|
|
|
+ return res1.toString();
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取当前手机系统版本号
|
|
|
*
|
|
|
* @return 系统版本号
|