android 获取 mac
时间: 2023-10-18 08:53:46 浏览: 137
Android获取MAC
Android获取MAC地址的问题可以通过使用WifiManager的getMacAddress()接口来解决。然而,在Android Q中,使用该接口获取到的MAC地址值为02:00:00:00:00:00,与真实值不符。为了获取真实的MAC地址,可以使用WifiManager的getFactoryMacAddresses()接口。具体的代码示例如下:
```java
WifiManager mWifiManager = (WifiManager) getActivity().getSystemService(WIFI_SERVICE);
String\[\] macAddresses = mWifiManager.getFactoryMacAddresses();
String macAddress = null;
if (macAddresses != null && macAddresses.length > 0) {
macAddress = macAddresses\[0\];
}
if (TextUtils.isEmpty(macAddress)) {
// MAC地址不可用
mWifiMacAddress.setSummary(R.string.status_unavailable);
} else {
// 使用获取到的真实MAC地址
mWifiMacAddress.setSummary(macAddress);
}
```
你可以参考\[2\]中的链接获取更多关于AbstractWifiMacAddressPreferenceController的信息。
#### 引用[.reference_title]
- *1* *2* *3* [Android Q 获取 Wifi MAC Address 返回 02:00:00:00:00:00 问题](https://blog.csdn.net/shenfengchen/article/details/114370416)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文