Ahmad Rizqi
Ahmad Rizqi

Reputation: 31

How to get Mac address in Kotlin

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

Answers (1)

Raka Adi Nugroho
Raka Adi Nugroho

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

Related Questions