获取Mac地址:
public static String GetMAC(Context context) { String Mac = ""; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { Mac = getMacAddress(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Mac = getMacFromHardware(); } return Mac;}private static String getMacAddress() { String Mac = null; String str = ""; try { Process pp = Runtime.getRuntime().exec("cat/sys/class/net/wlan0/address"); InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); while (null != str) { str = input.readLine(); if (str != null) { Mac = str.trim();//去空格 break; }
来源地址:https://blog.csdn.net/wxx314165038/article/details/131305199