FMX.SendCancelNotification Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to send and cancel notifications, and the use of the TNotification and TNotificationCenter classes.

Location

You can find the SendCancelNotification sample project at:

Description

The SendCancelNotification sample demonstrates how to send and cancel notifications, and the use of the TNotification and TNotificationCenter classes.

With this sample, you can do the following:

  • Send notifications immediately.
  • Send scheduled notifications.
  • Cancel scheduled notifications.
  • Cancel all notifications.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: SendCancelNotifications.dproj.
    • C++: SendCancelNotifications.cbproj.
  2. Select the target platform, iOS, Android, and OS X supported.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample:
    • Click Send Scheduled Notifications to schedule a notification to be fired in 10 seconds.
    • Click Send Notification Immediately to send a notification immediately.
    • Click Cancel Scheduled to cancel the scheduled notification.
    • Click Cancel All Notifications to cancel all notifications.

Files

File in Delphi File in C++ Contains

SendCancelNotifications.dproj

SendCancelNotifications.cbproj

The project itself.

uMain.fmx

uMain.fmx

The main form where the components are located.

uMain.pas

SendCancelNotificationsPCH1.h, SendCancelNotificationsPCH1.cpp

Used to define and implement the sample.

Information.txt

Information.txt

Further information about the sample.

Implementation

The TNotificationCenter component is the notification center; this component creates the notification.

The TNotification component is the notification itself.

Notification Details

After creating the notification, the sample sets the following notification details:

  • The Name field uniquely identifies a notification.
  • The AlertBody field adds the text of the notification.

Scheduling Notifications

FireDate is used to set the date and time when the notification is going to be fired.

  • Immediate Notifications: The sample sets the FireDate to Now for notifications that need to be fired immediately.
Note: By default, FireDate is set to Now, so if you do not change the value of FireDate, the notification is fired immediately.

Firing Notifications

After adding the information for the notification and adding the scheduling information, the sample uses the following sentence to send the notification to the notification center.

Delphi:

NotificationC.ScheduleNotification(Notification);

C++:

NotificationC->ScheduleNotification(Notification);

The following sentence is equivalent for immediate notifications, and you may also use PresentNotification to send notifications to the notification center when they have to be fired immediately.

Delphi:

NotificationC.PresentNotification(Notification);

C++:

NotificationC->PresentNotification(Notification);
Tip: Windows does not support scheduled notifications, you can present immediate notifications in Windows with PresentNotification.

Cancelling Notifications

The sample uses CancelNotification to cancel a scheduled notification indicating the Name of the notification.

The sample uses CancelAll to cancels all notifications:

  • The notifications that are scheduled will not be fired.
  • The notifications, that belong to this application, and are available in the notification center or notification drawer are also cancelled and removed.

Uses

See Also

Samples