0

Using the below code I am able to get the list of all signed in users. Is there a way to know which is the current active user?

 IReadOnlyList<User> users = await Windows.System.User.FindAllAsync();
Bells
  • 1,465
  • 1
  • 19
  • 30
  • If there are two game controllers, and a different person is holding each one, which is the "current active user"? You can ask each game controller for its User. That will tell you which user is holding each game controller. – Raymond Chen Jul 12 '16 at 06:47
  • @RaymondChen : If multiple users are signed in with a single controller, I am not able to identify the active user. – Bells Jul 12 '16 at 08:19
  • Now sure how we got to multiple users signed in with a single controller. Anyway, what you do is you get the Gamepad and look at the User property. That will tell you which user is using that gamepad. (It may be null, meaning "I don't know who is using this gamepad, because they haven't signed in yet.") – Raymond Chen Jul 12 '16 at 14:55
  • @RaymondChen : I am able to get 4 users signed in with a single controller in Xbox One and there is option to switch between the users. `Gamepad.GamePads.First().User.NonRoamableId` has a different value than the users returned by `Windows.System.User.FindAllAsync();` – Bells Jul 13 '16 at 11:21
  • http://stackoverflow.com/questions/33308994/username-with-system-user seems to have some comments pointing the same issue, but no specific answer! – Bells Jul 13 '16 at 11:24
  • Presumably the User on the GamePad is the user currently using the controller. I can't explain why the NonRoamableId doesn't match. – Raymond Chen Jul 13 '16 at 14:30

1 Answers1

1

I recently ran into this problem myself, and posted about it here. Someone responded there, and gave me some pretty big hints, which in turn helped me to get this solved.

Here is the quick and dirty (my UWP is HTML/JavaScript based BTW):

First, include the WinJS library in your project, if you don't already have it. Then, you just need a little bit of code to grab the active user, when the application is launched...

WinJS.Application.addEventListener('activated', function (args) {
    args.detail.user // <-- the active user!!
});

In order for this to be of any use, you need to grant your VS Solution, the "userAccountInformation" capability. To do that:

  1. Open your Visual Studio solution (I am using VS 2015).
  2. Double click your appxmanifest file.
  3. Click the "capabilities" tab.
  4. Check the option titled, "User Account Information".
Bart
  • 6,694
  • 6
  • 43
  • 53