android - 在 Android 6.0 中获取 MAC 地址

标签 android wifi mac-address

我正在开发一个获取设备 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/

相关文章:

Android Listview 在 Keyboardview 之上

java - 从客户端获取mac

java - 如何获取远程机器的mac地址java

iphone - 如何在 iOS 中通过 3G 连接创建无线热点

java - 无法创建 WifiConfiguration

java - 为什么客户端套接字可以检测到服务器套接字关闭,但反之则不行?

ios - Apple是否允许在应用程序中显示设备的MAC地址

android - 使用 Cordova (Phonegap) 将 Xcode iPad 应用程序转换为 Android

java - 你如何列出网络上的所有 smb 服务器?

java - 安全标志 fstack-protector Realm library Android