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.
You could get AppDiagnosticInfo of all uwp apps that are running by the following code.
var list = await AppDiagnosticInfo.RequestInfoAsync();
And then you could get AppInfo from each item in the AppDiagnosticInfo 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>
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;
}