Android - How To Programmatically Switch Users By User Name?
I'm new to Android and I have to do an application at work that performs the following task: I listen to a socket that is supposed to send me a user name. After receiving the user
Solution 1:
Haven't tried it myself but you should be able to get all UserHandle setup on the device and then use DevicePolicyManager switchUser() method.
UserManagerum= (UserManager) getSystemService(USER_SERVICE);
List<UserHandle> userProfiles = um.getUserProfiles();
For this to work, you have to set your app as a device administrator (should not be a problem as you say it's an internal fully managed app)
Solution 2:
Did you manage to get the user names once you become the device owner ? getUserProfiles and getSecondaryUsers can be used, but they both return UserHandle. I can't get the user name registered at creation. It seems that the only way is to add the MANAGE_USERS permission to the manifest but that supposes the app to be a system app : https://developer.android.com/reference/android/os/UserManager#getUserName()
I think I will create a persistent list somewhere.
Post a Comment for "Android - How To Programmatically Switch Users By User Name?"