问题
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