Reputation: 31
I need to obtain the MAC address of my android device using Kotlin. I've searched online, but I haven't found anything useful. I am using WiFi MAC address as Unique id, How to get the actual MAC address of the Android device in Kotlin ?
Upvotes: 2
Views: 8974
Reputation: 4253
fun getMac(context: Context): String {
val manager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
val info = manager.connectionInfo
return info.macAddress.toUpperCase()
}
your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
default value if you don't have grant access is 02:00:00:00:00:00
Upvotes: 5