Greg Dawson
Greg Dawson

Reputation: 195

Toast Notifications do not work when application packaged into Appx package

I have developed a Microsoft Store app and I want to add Toast notifications.

The application is developed using Delphi 10.2.3 and I am using "Desktop Bridge" technology to convert it into an Appx package for the Microsoft Store. Toast Notifications works fine until I package the application into an Appx package (for the Store or Sideloading).

When running from appx and SideLoading, Toast notifications do not work and my app is not listed in the Windows Settings as a notification sender. I figured there must be some manifest extension I need to define. There was a (now deprecated) appxmanifest setting ToastCapable="true", but I am reading that is no longer used nor required for Windows 10.

I have Toast Notification working just fine when I run the application executable, but not when I install it from an Appx package. How do I get Windows 10 to understand my application is a Notification Sender?

Upvotes: 3

Views: 691

Answers (1)

Alain Thiffault
Alain Thiffault

Reputation: 608

Unfortunately it will not work using the provided TNotificationCenter component (I tested in many versions including 10.2.3).

The reason is described in this link: https://blogs.msdn.microsoft.com/universal-windows-app-model/2017/01/31/how-to-ensure-your-toast-notifications-continue-to-work-when-converting-your-win32-app-into-a-windows-store-app-using-project-centennial/

There is a simple fix but you need to modify the component source code. When publishing to the Windows Store, TNotificationCenter should not create a shortcut for your app and should not provide an application ID when creating the IToastNotifier instance. This will be done automatically for you.

I ended up writing my own library to manage Windows 10 notifications because I wanted more elaborate scenarios and custom XML payloads then what is offered but I can confirm that it works when done as per Microsoft instructions.

I compared my classes with System.Win.Notification (found in source\\rtl\common) and here are some tips that you could try to make it work (untested):

#1 - constructor for TNotificationCenterWinRT

FToastNotifier := TToastNotificationManager.Statics.CreateToastNotifier(LWSAppID);

should be ...

FToastNotifier := TToastNotificationManager.Statics.CreateToastNotifier();

#2 - TNotificationCenterWinRT.DoPresentNotification

if CreateShortcut then

should be ...

if True then

Note: if you decided to modify the source file, it is recommended to first make a copy of the file in your project folder and modify that instead.

Upvotes: 5

Related Questions