Reputation: 553
According to UserManager Documentation, there's some public methods like the getUserName()
, when I call the function as below and I compile, I get the error: Unresolved reference: getUserName
package com.example
import android.Manifest
import android.os.UserManager
class DeviceInfo(private val context: Context) {
val userName: String
get(){
return UserManager.getUserName()
}
}
How can I call this public function in Kotlin?
Upvotes: 0
Views: 148
Reputation: 148
Try the following code, it should solve your problem
class DeviceInfo(private val context: Context) {
val userName: String
get(){
val um = context.getSystemService(Context.USER_SERVICE) as UserManager
return um.userName
}
}
Upvotes: 3