2

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 ?

Ahmad Rizqi
  • 31
  • 1
  • 2
  • here https://stackoverflow.com/questions/11705906/programmatically-getting-the-mac-of-an-android-device – Hoàng Vũ Anh Dec 17 '19 at 02:35
  • To convert Java code in Android studio use CTRL+SHIFT+ALT+K – Hoàng Vũ Anh Dec 17 '19 at 02:36
  • See "[Best practices for unique identifiers](https://developer.android.com/training/articles/user-data-ids)" to learn which identifiers are appropriate for your use case. Note in particular that that page says: "[I]t's generally not recommended to use MAC address[es] for any form of user identification." Can you explain why you need a "Unique ID" here? – Peter O. Dec 17 '19 at 04:08

1 Answers1

5
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

Raka Adi Nugroho
  • 3,403
  • 1
  • 8
  • 6