Android receives Mac and IP addresses of mobile phones

Source: Internet
Author: User

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 ();

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.