SHIN JaeGuk
SHIN JaeGuk

Reputation: 511

How to let a toast notification stay in Windows 10 Action Center with Delphi

I use Delphi 10.2 in Windows 10. The following code is the sample code provided by Embarcadero.

After running this code the notification disappears and deosn't stay in Action Center. How can I let it pended there?

procedure TNotify.btnShowClick(Sender: TObject);
var
  MyNotification: TNotification;
begin
  MyNotification := NotificationCenter1.CreateNotification;
  try
    MyNotification.Name := 'Windows10Notification';
    MyNotification.Title := 'Windows 10 Notification #1';
    MyNotification.AlertBody := 'RAD Studio 10 Seattle';

    NotificationCenter1.PresentNotification(MyNotification);
  finally
    MyNotification.Free;
  end;
end;

ADDED: After turning on the toggle of Windows Setting > System > Notifications & actions I can see HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Embarcadero.DesktopToasts.0579D43A\ShowInActionCenter is 1. But each user who would use this application can't do this all the time manually and I cannot predict the name of the key either.

Upvotes: 10

Views: 5296

Answers (1)

Fritzw
Fritzw

Reputation: 522

You will find the answer here: powershell script creates Windows 10 notification and it disappears after popup

You must register your application for "Show notifications in action center" "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$prodName" -Name "ShowInActionCenter" -Type Dword -Value "1"

To get the $prodName use:

function TNotificationsForm.getRegisterToastMessageKey : String;
const
  AppId = 'Embarcadero.DesktopToasts.';
begin
  result := AppId + THashBobJenkins.GetHashString(ParamStr(0));
end;

Embarcadero hasn't done a good Job here but so you get the Key, or make a copy from unit System.Win.Notification and change it to your needs.

Upvotes: 5

Related Questions