With Android Target Version = 29, Compile SDK = 29
I got Wifi Mac Address in Android 10, 11, 12, But I can't get WiFI Mac Address in Android 13 only.
we Got Default Mac Address only 02:00:00:00:00:00.
Not Gettting Correct Mac Address Which is availabe in Wifi
Build.gradle File
plugins {
id("com.android.application")
}
android {
namespace = "com.mantra.wifimacaddress"
compileSdk = 29
defaultConfig {
applicationId = "com.mantra.wifimacaddress"
minSdk = 24
targetSdk = 29
versionCode = 1
versionName = "1.0"
multiDexEnabled = true
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("com.google.android.material:material:1.2.1")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("com.karumi:dexter:6.2.3")
}
Get Mac Address
public String getMacAddr() {
try {
WifiManager wifiManager = (WifiManager) MainActivity.this.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
String ssid = info.getSSID();
String bssid = info.getBSSID();
System.out.println("Get SSID ====> " + ssid + " Get BSSID====> " + bssid);
List<NetworkInterface> 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(Integer.toHexString(b & 0xFF) + ":");
res1.append(String.format("%02X:", b));
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return "02:00:00:00:00:00";
}
A right MAC Address cannot be get from many years. Any non-rooted method will give only fake values. There are tons of articles online about this behaviour. It's due to privacy settings of OS. It's a security feature. It cannot be bypassed.