简体   繁体   中英

C# - UWP AppInfo throws NotImplementedException

I'm developing a C# WinForms app, using the UWP API. I'm attempting to read notifications programatically, and I have succeeded so far. However, whenever I call AppInfo from the UserNotification class, I get a NotImplementedException, no matter what property I read from AppInfo.

Does anyone have any suggestions?

I have only been able to find 1 answer to this question and it's not very useful, and also a few years old. This is a major roadblock in my project, any help is massively appreciated!

Thank you in advance.

EDIT

Here's my code.

        try {
            this.source = notification.AppInfo.DisplayInfo.DisplayName;
        } catch(NotImplementedException e) {
            this.source = "Unspecified";
        }

        NotificationBinding binding = notification.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
        if (binding != null) {
            Console.WriteLine(binding.GetTextElements()[1]);
            this.title = binding.GetTextElements().FirstOrDefault()?.Text;
            this.body = string.Join("\n", binding.GetTextElements().Skip(1).Select(t => t.Text));
        }
        Init();

I'm using the code from the examples in the docs.

UWP AppInfo throws NotImplementedException

Based on the exception message, it looks like notification.AppInfo.DisplayInfo has not been implemented for WinForm platform. For this scenario, we have a workaround for getting AppInfo with [AppDiagnosticInfo][1] api. Please refer the following code

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;
    var display = currentAppInfo.DisplayInfo;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM