问题
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();
回答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:
- Open your Visual Studio solution (I am using VS 2015).
- Double click your appxmanifest file.
- Click the "capabilities" tab.
- Check the option titled, "User Account Information".
来源:https://stackoverflow.com/questions/38321167/find-currently-active-user-in-xbox-one-uwp