Android - How to programmatically switch users by user name?

后端 未结 2 1437
轮回少年
轮回少年 2021-01-14 15:04

I\'m new to Android and I have to do an application at work that performs the following task:

  1. I listen to a socket that is supposed to send me a user name.
2条回答
  •  梦毁少年i
    2021-01-14 15:35

    Haven't tried it myself but you should be able to get all UserHandle setup on the device and then use DevicePolicyManager switchUser() method.

    UserManager um = (UserManager) getSystemService(USER_SERVICE);
    List 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)

提交回复
热议问题