Get the MAC address of your Android device without Wi-Fi

How to get the MAC address of the network interface of an Android device that does not have a Wifi interface (for example, an Android emulator)? WifiInfo received through WifiManager returns null.

EDIT

To be more clear: I need to contact an existing network protocol (not developed by me) on the local network, where I have to send the MAC address of the communication interface within the payload at the registration stage.

+21
android mac-address
May 31 '11 at 18:25
source share
5 answers

Reading / sys / class / net / [something] / address as a text file

But it is unlikely to be useful in the way you think.

+17
May 31 '11 at 10:21
source share

I'm going to take a leap and assume that you want this MAC address to set a unique device identifier. Mac addresses are not a way to do this.

There is an Android Developer blog entry titled β€œ Identifying Application Installs,” which pretty well describes the topic of generating a unique identifier, including popular methods and pros / cons. It's definitely worth a read. Very relevant for this message is the following quote:

It may be possible to get the Mac address from WiFi or Bluetooth devices. We do not recommend using this as a unique identifier. For starters, not all devices have WiFi. Also, if Wi-Fi is not turned on, the hardware may not report the Mac address.

Options available to you include TelephonyManager.getDeviceId (), android.os.Build.SERIAL and Settings.Secure.ANDROID_ID, all of which are described in more detail in the related message.

+23
May 31 '11 at 19:37
source share

See this post where I presented an example of Utils.java for implementing pure-java.

Utils.getMACAddress("wlan0"); Utils.getMACAddress("eth0"); Utils.getIPAddress(true); // IPv4 Utils.getIPAddress(false); // IPv6 
+4
Oct 22 '12 at 8:16
source share

What is the network interface on which you want to get the MAC address? If there is no wifi, you, of course, cannot get the MAC address of the Wi-Fi device. It represents physical equipment, and if not, it simply does not exist.

+2
May 31 '11 at 18:28
source share

To get the MAC address of a Wi-Fi Android device using adb: adb shell getprop ril.wifi_macaddr

Use the following Java code to programmatically program it:

 Process p = Runtime.getRuntime.exec("adb", "shell", "getprop", "ril.wifi_macaddr") BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()); String macAddress = br.readLine(); 
0
Jan 17 '14 at 9:18
source share



All Articles