From: http://orgcent.com/android-wifi-mac-ip-address/ |
Blog of radish Cabbage
I thought that the MAC address of the Wi-Fi network card could not be obtained without enabling the WiFi function. After the real machine test, I found that only the obtained MAC address is 0, of course, no IP address is allocated when WiFi is not connected. Take a look at the following details:
<Uses-Permission Android: Name = "android. Permission. access_wifi_state"/>
// If WiFi is not enabled, you can still obtain the MAC address. However, the IP address must be in the connected status. Otherwise, the value is 0.
String macaddress = NULL, IP = NULL;
Wifimanager wifimgr = (wifimanager) getsystemservice (context. wifi_service );
Wifiinfo info = (null = wifimgr? Null: wifimgr. getconnectioninfo ());
If (null! = Info ){
Macaddress = info. getmacaddress ();
IP = integer. tostring (info. getipaddress ());
}
System. Out. println ("Mac:" + macaddress + ", IP:" + IP );
Method 2:
PublicStringgetlocalmacaddress (){
Wifimanager WiFi = (wifimanager) getsystemservice (context.Wifi_service);
Wifiinfo info = wifi. getconnectioninfo ();
ReturnInfo. getmacaddress ();
}