How to get current AppInfo in UWP environment

后端 未结 2 1148

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 20:47

    You could get App​Diagnostic​Info of all uwp apps that are running by the following code.

    var list = await App​Diagnostic​Info.RequestInfoAsync();
    

    And then you could get AppInfo from each item in the App​Diagnostic​Info list.

    foreach (var diagnosticinfo in list)
    {
        info = diagnosticinfo.AppInfo;
    }
    var id = info.Id;
    

    Please note that you need to declare the following capabilities in the Package.appxmainfest.

    <Package
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
    IgnorableNamespaces="uap mp rescap">
      <Capabilities>
        <rescap:Capability Name="appDiagnostics" />
      </Capabilities>
    </Package>
    
    0 讨论(0)
  • 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.

    <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"     xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap">
      <Capabilities>
        <Capability Name="internetClient" />
        <rescap:Capability Name="appDiagnostics"/>
      </Capabilities>
    </Package>
    

    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;
    }
    
    0 讨论(0)
提交回复
热议问题