Original: http://blog.csdn.net/suziluo123/article/details/51382410
Recently contacted 6.0, found using a simple wifiManager.getConnectionInfo().getMacAddress(); method to obtain a MAC address. Google later found that Google's access to hardware information, its control more stringent. The SD card reads and writes, in addition to the Authority Declaration, should also request dynamically, otherwise will be forbidden. As for MAC network address acquisition, the latest result returned by the corresponding API is 02:00:00:00:00:00 this fixed value. You can see Getting MAC address in Android 6.0.
According to the official explanation, this is to 更好的数据保护 see the Android 6.0 change article in the Access to Hardware Identifier section.
Traditional ways to get a MAC:
final WifiManager wifiManager = (WifiManager) getApplication() .getApplicationContext().getSystemService(Context.WIFI_SERVICE);final String wifiMACaddress = wifiManager.getConnectionInfo() .getMacAddress();
However, this method 6.0 does not do a very well, how to do?
Query the data to find a corresponding solution:
Api--networkinterface.getnetworkinterfaces (), which uses Java to obtain device network device information, can still obtain the MAC address indirectly.
//interested friends can see how networkinterface is implemented in the Android framework Public StaticString macAddress ()throwssocketexception {String address=NULL; //storing the access network interface on the current machine in the enumeration collectionenumeration<networkinterface> interfaces =networkinterface.getnetworkinterfaces (); while(Interfaces.hasmoreelements ()) {NetworkInterface netWork=interfaces.nextelement (); //If there is a hardware address and can be accessed with the given current permission, the hardware address (usually MAC) is returned. byte[] by =network.gethardwareaddress (); if(by = =NULL|| By.length = = 0) { Continue; } StringBuilder Builder=NewStringBuilder (); for(byteb:by) {Builder.append (String.Format ("%02X:", b)); } if(Builder.length () > 0) {Builder.deletecharat (Builder.length ()-1); } String mac=builder.tostring (); LOG.D ("Mac", "Interfacename=" +network.getname () + ", mac=" +mac); //from the MAC address List of the online device on the router, you can verify that the device WiFi name is Wlan0 if(Network.getname (). Equals ("Wlan0") {LOG.D ("Mac", "InterfaceName =" +network.getname () + ", mac=" +mac); Address=mac; } } returnaddress; }
This will be able to get to the 6.0 MAC address normally! I hope we can help you.
About getting android6.0 's MAC address