How to get MAC address of the WIFI interface in android?

15,717

You can't. Depending on the device, if the wifi adapter is disabled then it may actually be electronically switched off, so you can't read any info from it.

From the Android Developers Blog:

Mac Address

It may be possible to retrieve a Mac address from a device’s WiFi or Bluetooth hardware. We do not recommend using this as a unique identifier. To start with, not all devices have WiFi. Also, if the WiFi is not turned on, the hardware may not report the Mac address.

Share:
15,717
Himberjack
Author by

Himberjack

Updated on June 12, 2022

Comments

  • Himberjack
    Himberjack about 2 years

    I am using the following code:

    WifiManager wifiMgr = (WifiManager) app.getSystemService(Context.WIFI_SERVICE);
    return wifiMgr.getConnectionInfo().getMacAddress();
    

    Problem is, the WIFI must be ENABLED in the device in order for me to read its address. How can I still read the MAC of the WIFI even if the WIFI is off?

  • Himberjack
    Himberjack about 13 years
    What is the best way to identify the unique serial of a device then?
  • Graham Borland
    Graham Borland about 13 years
    See this Android Developer Blog article: android-developers.blogspot.com/2011/03/…
  • Johann
    Johann over 11 years
    Nonsense. Even if the Wi-Fi is off, the MAC address can be read. Even the OS does this when you view the MAC address under the phone's settings.
  • Graham Borland
    Graham Borland over 11 years
    @AndroidDev go ahead and provide a better answer, then. Please provide references, and sample code for how you would go about reading the MAC address with the adapter disabled. How do you know the settings screen isn't just displaying a cached string?
  • Graham Borland
    Graham Borland over 11 years
    This is exactly what the OP has already tried. Read the question. And also read the Android Developer blog article, which confirms that this simply does not work on many devices if the adapter is disabled. android-developers.blogspot.com/2011/03/…
  • tejas
    tejas about 11 years
    Does this gets the MAC address without Wifi but mobile data enabled?
  • Sudarshan Vidhate
    Sudarshan Vidhate over 8 years
    I think Access to Hardware Identifier is not allowed from Android 6.0 & Above. developer.android.com/about/versions/marshmallow/…