Error “The method createUser(String, int) is undefined for the type UserManager”
-
21-12-2019 - |
Question
I am trying to create new User using UserManager
service on android KK 4.4 ( Multi-user)
mUserManager = (UserManager)getSystemService(Context.USER_SERVICE);
mUserManager.createUser("USER NAME", 0);
I can access all other APIs in UserManager
using mUserManager
without giving any error but createUser
is showing error "The method createUser(String, int)
is undefined for the type UserManager
".
I can see createUser
is defined in UserManager
class.
Can somebody please help me on this in case there's anything I am missing.
Solution
If you refer to the documentation for UserManager
, you'll see that no createUser
method is listed. Even though the method is defined in the Android source code, and exists in the framework installed on the device, it's not part of the public API, so it's not present in the Android SDK; that is, it isn't in the android.jar that you link your app against.
It may still be possible to access it using reflection, but I rather suspect that the service backing this call will disallow non-system apps from calling it, in which case you'll get a SecurityException
at runtime.