问题描述
在以编程方式检索设备的MAC地址时遇到问题,在任何人提及其他帖子之前,我已经阅读了它们,例如:如何以编程方式找到Android设备的MAC地址
I'm having an issue with retrieving the MAC address of the device programatically, before anyone mentions anything about other posts I have read them already such as:How to find MAC address of an Android device programmatically
但是我尝试在自己的应用程序中使用该代码,并使用简单的log.d对其进行了测试,结果发现它什么也没有返回.消息看看是否可行"显示,但没有其他消息.所以我假设mac地址为空.
however I tried using the code with my own application and tested it with a simple log.d, only to find that it is returning nothing. The message of "seeing if this works shows" but nothing else. So i am presuming the mac address is null.
Log.d("seeing if this works", macAddress2);
我所做的代码如下所示:
The code of what I have done is shown here:
//Set onclick listener for the Get Mac Address button
getMac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress2 = wInfo.getMacAddress();
macAddress.setText(macAddress2);
}
});
推荐答案
您正在测试哪个Android版本?最新(2015年10月10日) Android M预览已阻止该应用获取Wifi和蓝牙的硬件标识符.
Which Android version are you testing on? The latest(10/2015) Android M preview has blocked the app from getting the hardware identifiers for Wifi and Bluetooth.
有一种解决方法,可以从/sys/class/net/wlan0/address
读取Wifi MAC,但是在 Android N 中也将其作为 Google宣称.
There is a workaround by reading the Wifi MAC from /sys/class/net/wlan0/address
, which however will also be blocked in the Android N as claimed by Google.
这篇关于以编程方式检索MAC地址-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!