4
{
    try {
        List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface nif : all) {
            if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

            byte[] macBytes = nif.getHardwareAddress();
            if (macBytes == null) {
                macTestResultString = "";
            }
        }
    } catch (Exception ex) {
        Log.e(App.TAG, EXCEPTION + ex.getMessage());
    }
    return macTestResultString;
}
auspicious99
  • 3,902
  • 1
  • 44
  • 58
viki_rvc
  • 53
  • 1
  • 6
  • Please read the changes in Android 11 https://developer.android.com/training/articles/user-data-ids#mac-11-plus Without root you wont be able to get the mac address – tyczj Jul 21 '21 at 14:57

1 Answers1

1

Getting mac address on device api more than 10 is almost impossible. Android's new security restriction no longer allow to access mac address read here. Why do you need the mac address mention the reason might be there is some other solution that may help.

Programmerabc
  • 329
  • 2
  • 10
  • is there any way to get mac address even with security permissions? – Mostafa Imani Feb 19 '23 at 08:06
  • For android version < 6 refer: https://stackoverflow.com/a/11705949/16441984. For android version >= 6 due to security reasons mac address can't be retrieved and will return constant value. – Programmerabc Mar 16 '23 at 08:39