我正在开发一个获取设备 MAC 地址的应用程序,但由于 Android 6.0 我的代码无法工作,给我一个不正确的值。
这是我的代码...
public String ObtenMAC()
{
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
return(info.getMacAddress().toUpperCase());
}
它返回的不是真正的 MAC 地址,而是一个奇怪的代码:02:00:00:00:00:00
。
最佳答案
请引用Android 6.0 Changes .
To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
关于android - 在 Android 6.0 中获取 MAC 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33159224/