Android obtains mac addresses. android obtains mac addresses.

Source: Internet
Author: User

Android obtains mac addresses. android obtains mac addresses.

Http://www.cnblogs.com/xioapingguo/p/4037513.html

Find it online, record it

public static String getMacAdress(){        WifiManager wifi = (WifiManager) sContext.getSystemService(Context.WIFI_SERVICE);          WifiInfo info = wifi.getConnectionInfo();          return info.getMacAddress();    }

Remember to add the permission <uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"> </uses-permission>


How does android obtain the Ethernet mac address?

This article describes how to obtain the wireless network and Ethernet mac address: 1. obtain the mac address over ethernet because the set-top box system is Linux kernel. If the ethernet is eth0, you can read the related information from the following file:/sys/class/net/eth0/address Method 1: public static String loadFileAsString (String filePath) throws java. io. IOException {StringBuffer fileData = new StringBuffer (1000); BufferedReader reader = new BufferedReader (new FileReader (filePath); char [] buf = new char [1024]; int numRead = 0; while (numRead = reader. read (buf ))! =-1) {String readData = String. valueOf (buf, 0, numRead); fileData. append (readData);} reader. close (); return fileData. toString ();}/** Get the STB MacAddress */public String getMacAddress () {try {return loadFileAsString ("/sys/class/net/eth0/address "). toUpperCase (). substring (0, 17);} catch (IOException e) {e. printStackTrace (); return null ;}} Method 2: NetworkInterface NIC = NetworkInterface. getByName (" Eth0 "); byte [] buf = NIC. getHardwareAddress (); for (int I = 0; I <buf. length; I ++) {mac = mac + byteHEX (buf);} if (mac! = Null &&! "". Equals (mac) {} 2. to obtain mac and ip addresses from wifi, you must first go to manifest. add permissions to the xml file: <uses-permission android: name = "android. permission. ACCESS_WIFI_STATE "> </uses-permission> The following WifiManager wifi = (WifiManager) getSystemService (Context. WIFI_SERVICE); WifiInfo = wifi. getConnectionInfo (); return info. getMacAddress (); public String getLocalIpAddress () {try {for (Enumeration <NetworkInterface> en = NetworkInterface. getNetworkInterfaces (); en. hasMoreElements ();) {Net ...... remaining full text>

How can I view the Mac address of an Android phone?

It's easy to go To the WLAN settings in the settings, and then press the menu key of the mobile phone. A small interface is displayed at the bottom of the screen. Go to the Advanced page, where you can see the MAC address or settings and enter the phone information about the mobile phone.
And then select the hardware information. The MAC address is also displayed. This method is also applicable to mobile phones on other Android platforms.

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.