How to get Wi-Fi Mac address in Android Marshmallow

后端 未结 2 922
走了就别回头了
走了就别回头了 2020-12-03 21:24

I am using WiFi MAC address as Unique id, from Marshmallow onwards returning fake MAC address(for security reason). With this my Android application behav

相关标签:
2条回答
  • 2020-12-03 22:08

    I went to my Netgear router interface and looked for the tab listing connected devices which nicely produced the MAC ID.

    If in doubt, turn off the device and view the list, then turn it on and view again. The new listing is your MAC ID. Edit the router listing to show that.

    A bigger view, how could they really hide you MAC ID since it's one of primary identifiers for the world wide surveillance state?

    0 讨论(0)
  • 2020-12-03 22:16

    There is a work-around to get the Mac address in Android 6.0.

    First you need to add Internet user permission.

    <uses-permission android:name="android.permission.INTERNET" />
    

    Then you can find the mac over the NetworkInterfaces API.

    public static String getMacAddr() {
        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 "";
                }
    
                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) {
        }
        return "02:00:00:00:00:00";
    }
    

    Source: http://robinhenniges.com/en/android6-get-mac-address-programmatically

    0 讨论(0)
提交回复
热议问题