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

前端 未结 2 1812
感情败类
感情败类 2021-01-01 00:34

I am using the following code:

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


        
相关标签:
2条回答
  • 2021-01-01 01:12

    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.

    0 讨论(0)
  • 2021-01-01 01:13
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    String mac = wm.getConnectionInfo().getMacAddress();
    
    0 讨论(0)
提交回复
热议问题