Extend your mobile apps and increase user engagement with push triggers

Posted by on in Blogs
Today, I thought I would expand on my recent blog post that covered our new push notification support that we introduced in RAD Studio XE6.

One of the messaging features available via Kinvey (popular Backend-as-a-Service provider) is the support for push triggers.

Push triggers are a great way of increasing user engagement with your application by automatically 'triggering' a push notification any time a change is made to your app's data collection (either by updating an existing record or inserting a new record).

I thought I would expand our ToDo List demo that ships with Delphi and C++Builder to send a notification any time a user changes a record. For example, if your family or team at work uses a ToDo list to keep track of chores or tasks, you will see a notification on your Android or iOS device any time someone changes the item or adds a new todo item. The C++ and Delphi versions of the ToDo List demo project can be accessed on SourceForge.

Following my previous tutorial, I just copied and pasted my GCM (Google Cloud Messaging) AppID from my other sample application into my KinveyProvider component on my Datamodule. In addition, I also copied and pasted my revised AndroidManifest.xml filed into my BaaS ToDo List project folder.

In a production environment, you would be setting up and using a unique GCM AppID for each application. One thing to keep in mind when reusing the same AppID for testing is to make sure that you don't still have the other app installed on your device that previously used that GCM AppID. I then dropped a TPushEvents component onto my BaaSToDoList form and connected it to my TKinveyProvider component that lives on my DataModule.

I parented a TLabel to Layout5 and aligned it to Contents, with a slight left margin of 3 (so that the text doesn't run too close to the left side of the form). I set TLabel's Visible property to False, and parented a GlowEffect to the label to make it stand out a little more once it is shown below the list.

I also placed a TTimer component onto my form, set Enabled to False and set an Interval of a couple of seconds, i.e. 3000 to show the Label for a couple of seconds as soon as the list has been changed.

I then setup the following OnTimer event:
procedure TBaaSToDoList.Timer1Timer(Sender: TObject);
ItemChangeLabel.Text := '';

I also setup the following OnPushReceived event:
procedure TBaaSToDoList.PushEvents1PushReceived(Sender: TObject;
const AData: TPushData);
if DataModule1.ItemAdapter.State = TBindSourceAdapterState.seBrowse then
DataModule1.ItemAdapter.Active := True;
Timer1.Enabled := True;
ItemChangeLabel.Visible := True;
ItemChangeLabel.Text := 'The list has been changed';

Next, I setup my push trigger by going to AddOns > Messaging > Push Triggers inside my Kinvey account. I set my collection to the 'ToDos' collection type that I defined in my ToDoItemTypes unit that is part of my BaaS demo project and showed in my previous blog post. For reference, I am including a section of that code so you can see where the data collection name was defined in my code.
TToDoNames = record
TitleProperty = 'Title';
ContentProperty = 'Content';
BackendClassname = 'ToDos';
TitleElement = 'title';
ContentElement = 'content';

The recipient is 'testuser' since that is the only user I have defined so far under AddOns > Core > Users.

For my message template (the notification that is seen in Android's Notification Center when the app is not running or is running in the background), I wanted to include the title of the item that was either added or changed. That is done by including {{request.body.title}} in the message template. Per the info on Kinvey.com, "saves (inserts and updates) to the above collection will trigger this push notification".

I thought it would be nice to run this app on Windows (using the Windows preview style) and add my records on Windows to then be notified on my Android device (or inside my Android app) of any changes that have been made to my ToDo List application.

Gold User, Rank: 5, Points: 558
Senior Product Manager, RAD Studio
Comments are not available for public users. Please login first to view / add comments.