Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 445
SHIN JaeGuk Avatar asked Mar 04 '18 10:03

SHIN JaeGuk


People also ask

How do I stop Windows notifications from disappearing?

-Settings > system > notifications > turn on notifications and in the list below, select the apps you want to receive notifications. Now click on Focus Assist > check Disabled.

How do I add apps to the Notification Center in Windows 10?

Go to Settings > System > Notifications & actions‌ , under Get notifications from these senders select the app, and then under Priority of notifications in action center select Top.


1 Answers

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.

like image 155
Fritzw Avatar answered Oct 17 '22 04:10

Fritzw