Android获取mac地址、OA地址和外网IP地址

1、获取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;

}


/**
 * Android 6.0-Android 7.0 获取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;
            }
     

猜你喜欢

转载自blog.csdn.net/wxx314165038/article/details/131305199