Ami*_*ela 5 android operating-system mac-address android-11
我们用来获取 MAC 地址,但从Android 11 中的 MAC 地址可用性变化NetworkInterface.getHardwareAddress()可以看出,现在它不会用于Android\xc2\xa011。
有解决方案或任何指南吗?
\n在我的 Android 项目中,我使用以下代码来获取适用于所有 Android 版本的 MAC 地址。
但现在已经不复存在了……所以现在我们无法获取 MAC 地址。请参阅不使用 MAC 地址。
我们用来获取 MAC 地址的旧方法:
public static String getMacAddress() {
    try {
        List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface networkInterface : all) {
            if (!networkInterface.getName().equalsIgnoreCase("wlan0"))
                continue;
            byte[] macBytes = networkInterface.getHardwareAddress();
            if (macBytes == null) {
                return "";
            }
            StringBuilder res1 = new StringBuilder();
            Log.e("Get MAC address", "getMacAddr: " + res1.toString());
            for (byte b : macBytes) {
                // res1.append(Integer.toHexString(b & 0xFF) + ":");
                res1.append(String.format("%02X:", b));
            }
            if (res1.length() > 0) {
                res1.deleteCharAt(res1.length() - 1);
            }
            return res1.toString().replace(":", "-");
        }
    } catch (Exception ex) {
        Log.e("TAG", "getMacAddr: ", ex);
    }
    return "";
}
| 归档时间: | 
 | 
| 查看次数: | 14392 次 | 
| 最近记录: |