在 Android 中获取蓝牙适配器的 MAC 地址

Get the MAC address of bluetooth adapter in Android

我正在尝试获取 android 设备中蓝牙的 MAC 地址。所以我使用以下方法:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String macAddress = mBluetoothAdapter.getAddress();

返回的地址是02:00:00:00:00:00。我看到一些问题和帖子说不可能再在 android 中获取您的 MAC 地址,除非您的应用程序是 系统应用程序.

如果我真的需要获取我的 phone 的 MAC 地址怎么办?是做不到还是怎样?

注意:我知道这个问题在 SO 上被问了很多次,但大多数答案都已过时。

出于安全原因,此功能在 Android 上不可用,因为 Android 版本 6.0 [source]:-

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.

这样做的原因是为了阻止随机应用程序获取有关 phone 的硬件地址的信息,从而违反 privacy/data 保护。

希望对您有所帮助。

前面的回答Youssif Saeed说的是对的。 Android 不会再让我们得到 MAC 地址了。

简单描述一下我想要的东西:

Let's say I have a phone with MAC Address X, and I have another nearby device with MAC address B. When the two devices are nearby each other. I was able to get the MAC address of the other device using BluetoothDevice and getAddress() method from ScanResult.getDevice(). So what I still need is to catch my own device MAC address so that in the backend I save each user with his MAC address, and when I catch it in bluetooth, I know who's nearby me

这是我为了在附近的设备之间发送一些数据而采取的解决方法。

我找到了一个叫做 Nearby Messages API 的东西。它适用于 AndroidiOS,并且非常容易实现。现在,我能够捕获安装了我的应用程序的附近设备,并发送应用程序生成的唯一 ID 来识别用户。