M.kazem Akhgary
M.kazem Akhgary

Reputation: 19179

How to get current AppInfo in UWP environment

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.

Upvotes: 0

Views: 1280

Answers (2)

Nico Zhu
Nico Zhu

Reputation: 32785

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>

Upvotes: 1

Ann Yu
Ann Yu

Reputation: 137

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;
}

Upvotes: 1

Related Questions