FMX.Birthday Reminder Sample
This demo is an FMX application that shows how to use the TAddressBook component to access the Address Book on an Android or iOS device.
You can find the Birthday Reminder sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples, and then navigate to:
Object Pascal\Multi-Device Samples\Device Sensors and Services\Address Book\BirthdayReminder
CPP\Multi-Device Samples\Device Sensors and Services\Address Book\BirthdayReminder
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
This sample demonstrates how to:
- Request permission to access the Address Book.
- Retrieve contacts from the Address Book.
- Show notifications to remember birthdays.
The sample uses a TNotificationCenter component to send notifications.
How to Use the Sample
- Navigate to the location given above, and open:
- Delphi: BirthdayReminderDemo.dproj
- C++: BirthdayReminderDemo.cbproj
- Select Android or iOS Device as the Target Platform.
- Select the device.
- Press F9 or choose Run > Run.
Contacts Upload to the Address Book
- If permission is granted, the TListView is filled with contacts of the Address Book that have birth date information, and the TProgressBar is animated during the upload process.
- If permission in not granted, a message appears informing that the user is not allowed to read contacts.
Address Book Changes
When a contact is loaded, the ContactLoaded procedure defines a label next to the contact with the remaining days to the birthday. If the contact has a photo in the Address Book, the photo is shown at the left of the contact.
When the loading process starts, all the notifications are canceled.
- In Delphi:
- In C++:
PostNotification procedure is called in the ContactLoaded procedure.
PostNotification procedure creates and presents the notification when the birthday arrives.
- In Delphi:
Notification.RepeatInterval := TRepeatInterval.Year; //The interval for a repeating notification. Notification.FireDate := EventDate; //Date and time when the notification is fired. Notification.AlertBody := Format(NotificationMessage, [ADisplayName]); //The notification message text. Notification.EnableSound := True; //An alert is played when the notification appears. NotificationCenter1.ScheduleNotification(Notification); //Schedules a local notification for delivery at a specific date and time.
- In C++:
notification->RepeatInterval = TRepeatInterval::Year; //The interval for a repeating notification. notification->FireDate = eventDate; //Date and time when the notification is fired. notification->AlertBody = "Don't forget to congratulate " + displayName; //The notification message text. notification->EnableSound = true; //An alert is played when the notification appears. NotificationCenter1->ScheduleNotification(notification); //Schedules a local notification for delivery at a specific date and time