Does the Android Device Emulator have a MAC Address?

蓝咒 提交于 2019-12-08 21:44:11

问题


I wrote the following code to get the MAC address:

WifiManager wimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String address = wimanager.getConnectionInfo().getMacAddress();
Log.d("TOKEN", address);

This works perfectly on my phone, but in the Android emulator it returns null. Is this because the Android emulator doesn't have a MAC address?


回答1:


It's the same as when you try getting a hold of the bluetooth stuff on the emulator. There is no MacAdress and should return null. Try on a real device and it will work. The code is correct.




回答2:


See this post where I have submitted Utils.java example to provide pure-java implementations and works without WifiManager. Code works also in Emulator.

Utils.getMACAddress("wlan0");
Utils.getMACAddress("eth0");
Utils.getIPAddress(true); // IPv4
Utils.getIPAddress(false); // IPv6 



回答3:


By default, the Android emulator runs emulating a Ethernet connection, but not a wifi connection. Since the Wifi is not enabled, your code does not show a wifi mac address. See http://kmansoft.com/2010/07/27/debugging-wifi-in-the-emulator/

I found this answer very helpful when trying to view all the network devices and MacAddress on my device - https://stackoverflow.com/a/17719579/90236 to see



来源:https://stackoverflow.com/questions/10708421/does-the-android-device-emulator-have-a-mac-address

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