How to get current AppInfo in UWP environment

后端 未结 2 1150

How can I get the current AppInfo of the running UWP application? I could not find any accessible constructor or static function to get this information.

2条回答
  •  清歌不尽
    2021-01-27 21:09

    Make sure that your device is updated to Windows10 Creators Update version.
    Firstly, you should add Capability appDiagnostics to Package.appxmanifest. Directly to modify the code of the file.

    
      
        
        
      
    
    

    Then in the main code, get current package by matching the PackageFamilyName.

    var list = await AppDiagnosticInfo.RequestInfoAsync();
    var currentPackage = list.Where(o => o.AppInfo.PackageFamilyName == Package.Current.Id.FamilyName).FirstOrDefault();
    if (currentPackage != null)
    {
        AppInfo currentAppInfo = currentPackage.AppInfo;
    }
    

提交回复
热议问题