Does the Android Device Emulator have a MAC Addres

2019-06-20 06:12发布

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?

3条回答
冷血范
2楼-- · 2019-06-20 06:30

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.

查看更多
贼婆χ
3楼-- · 2019-06-20 06:43

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 
查看更多
来,给爷笑一个
4楼-- · 2019-06-20 06:43

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

查看更多
登录 后发表回答