Get android Ethernet MAC Address (not wifi interface)

后端 未结 8 1758
南旧
南旧 2021-02-05 12:12

I\'m using Android with Api level 8 and I want to get the Address of my Ethernet interface (eth0).

On API level 8, the NetworkInterface class don\'t have the function ge

8条回答
  •  野的像风
    2021-02-05 12:30

    this way to use java fix it; maybe can help you

    NetworkInterface netf = NetworkInterface.getByName("eth0");
    byte[] array = netf.getHardwareAddress();
    StringBuilder stringBuilder = new StringBuilder("");
    String str = "";
    for (int i = 0; i < array.length; i++) {
        int v = array[i] & 0xFF;
        String hv = Integer.toHexString(v).toUpperCase();
        if (hv.length() < 2) {
            stringBuilder.append(0);
        }
        stringBuilder.append(hv).append("-");                   
    }
    str = stringBuilder.substring(0, stringBuilder.length()- 1);
    

提交回复
热议问题