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

China☆狼群 提交于 2019-11-29 14:42:26

问题


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?


回答1:


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.




回答2:


WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String mac = wm.getConnectionInfo().getMacAddress();


来源:https://stackoverflow.com/questions/6276380/how-to-get-mac-address-of-the-wifi-interface-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!