Android 6.0后获取Wifi Mac & 蓝牙Mac

Wifi  Mac获取:https://www.jianshu.com/p/16d4ff4c4cbe

/**
 * 遍历循环所有的网络接口,找到接口是 wlan0
 * 必须的权限 
 * @return
 */
private static String getMacFromHardware() {
    try {
        List all = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface nif : all) {
            if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

            byte[] macBytes = nif.getHardwareAddress();
            if (macBytes == null) {
                return "";
            }

            StringBuilder res1 = new StringBuilder();
            for (byte b : macBytes) {
                res1.append(String.format("%02X:", b));
            }

            if (res1.length() > 0) {
                res1.deleteCharAt(res1.length() - 1);
            }
            return res1.toString();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "02:00:00:00:00:00";
}

作者:smart_dev
链接:https://www.jianshu.com/p/16d4ff4c4cbe
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

蓝牙地址获取:

https://stackoverflow.com/questions/33377982/get-bluetooth-local-mac-address-in-marshmallow

https://blog.csdn.net/jjf19891208/article/details/72831579

After that the application has to be signed with OEM / System key. Tested and verified on Android 8.1.0.

 



public static final String SECURE_SETTINGS_BLUETOOTH_ADDRESS = "bluetooth_address";

String macAddress = Settings.Secure.getString(getContentResolver(), SECURE_SETTINGS_BLUETOOTH_ADDRESS);

你可能感兴趣的:(Android,开发)