2

When creating notification using TNotificationCenter and TNotification, it only appear in the notification drawer, it won't have pop up mini floating box like WhatsApp msg notification for examples. Is there any properties that will enable that?

RenSword
  • 79
  • 8
  • 1
    You might want to join other social media Delphi groups, since not all types of beginner questions are allowed on SO. Please see my profile for some links... – Delphi Coder Dec 29 '21 at 12:12

1 Answers1

4

You need to create a channel with an importance of High, and have the notifications sent using the id for that channel (via the ChannelId property of the notification). Example code for setting up the channel:

procedure TForm1.SetupNotificationChannel;
var
  LChannel: TChannel;
begin
  LChannel := NotificationCenter.CreateChannel;
  try
    LChannel.Id := 'MyChannel';
    LChannel.Title := LChannel.Id;
    LChannel.Importance := TImportance.High;
    NotificationCenter.CreateOrUpdateChannel(LChannel);
  finally
    LChannel.Free;
  end;
end;

NotificationCenter is a TNotificationCenter component

Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
  • It works, thank you very much. May I ask what is the reason behind using try and finally block for LChannel and also TNotification? I saw TNotification examples always use that but can't find the reason why. – RenSword Dec 29 '21 at 09:11
  • 1
    https://lp.embarcadero.com/Object-Pascal-Handbook-2021 – Delphi Coder Dec 29 '21 at 09:15
  • 2
    It's the convention for creating/freeing objects. The call to `Free` in the `finally` block ensures that once created, the object will be freed regardless of whether an exception occurs within the `try` block. – Dave Nottage Dec 29 '21 at 09:15
  • @DaveNottage Thanks, I should built up my basic more. – RenSword Dec 29 '21 at 09:39
  • @DelphiCoder thanks, I have been wanting to find a free source of pascal book as a student. – RenSword Dec 29 '21 at 09:41