Find currently active user in xbox one UWP

≡放荡痞女 提交于 2019-12-13 04:33:10

问题


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:

  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".


来源:https://stackoverflow.com/questions/38321167/find-currently-active-user-in-xbox-one-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!