Remote push notifications on Android with RAD Studio XE6
Our BAAS framework in RAD Studio XE6 is based on our REST API framework. To enable push notifications on Android, we require Google Cloud Messaging (GCM) support to receive the push notifications. Parse does not currently support Google Cloud Messaging with their REST API, so if you are looking to use the same push notification service (BaaS) provider across both iOS and Android, I would recommend using Kinvey.
In this tutorial, I am going to show you how to setup and enable push notifications in your C++ and Delphi applications using XE6. The Delphi or C++ code is the same across iOS and Android, but the steps for setting up notifications are different on Android than on iOS, since you are connecting with Google Cloud Messaging (GCM) on Android and with Apple Push Notification (APN) on iOS.
In order to receive push notifications, you need to set up the messaging service (APS or GCM), the device, the cloud service (Kinvey), and your RAD Studio application. We have a great step-by-step tutorial on our docwiki that I recommend you look at since it walks you through all the steps.
My demo consists of a single form with a top aligned Toolbar and Label (to indicate the application name), and a client aligned ListView. The ListView will display each notification as a new item in the list. When the app is running in the background or is closed, you will see the notification displayed in the notification center on your device. On Android, you can access the notification center by swiping down from the top of your screen.
On my form, I placed 2 components:
- TPushEvent, connected to my KinveyProvider component, with the following event setup:
void __fastcall TForm3::PushEvents1PushReceived(TObject *Sender, const TPushData *AData)
{
ListView1->Items->Add()->Text = AData->Message;
}
Delphi
procedure TForm1.PushEvents1PushReceived(Sender: TObject;
const AData: TPushData);
begin
ListView1.Items.Add.Text = AData.Message;
end;
Next, you will need to setup the Messaging service. Please see this tutorial on how to register with Google and setup your push notification project. As part of that setup, you will be assigned a Project Number that you will need to enter on your Kinvey component, along with your Kinvey account info that you were provided when you signed up on Kinvey.com and setup the project.

BaaS uses OpenSSL, but for Android, those files already exist on the file system, so you don't need to add or link in any ssl library files. To send push notifications, you will need to login to your Kinvey.com account, go to Addons > Messaging > Push and connect your Kinvey account to your Google Cloud Messaging account:
- Copy:
- the Project ID from your Google Cloud Messaging Setup
- the API Key from your Google Cloud Messaging Setup


Comments
-
Paolo Pedrielli Monday, 25 July 2016
Hi Sarina,
I've a big problem with remote notification.
When the app is opened, everything works. When the app is closed, I receive the push notification but, when I click on it, my app opens but it stays to splash screen for a long time and then exit. I tried to check what event is fired but neither OnPushReceived and FormActivate are fired. What's wrong?
Thanks
Paolo -
Steve J Monday, 4 July 2016
Hi Sarina,
This looks fine and I was able to get my Kinvey messages pushed to iOS and my Android device.
The problem is that each time I modify my app, I suppress it from the Android device, deploy it, then it creates a new registration with Kinvey.
Then, instead of 1 push notification, I get as many notifications as I deployed a new version.
If I debug my app 15 times and deploy it to my Android tablet, then I will get 15 copies of my notification.
It seems to be a known behavior. How can we avoid the Android device to register each time? Any way to check the registration and skip it if Kinvey already has the Device ID?
(I am with Berlin 10.1)
iOS is fine, it shows only 1 notification.
Thanks
Steve -
sarinadupont Thursday, 17 April 2014
Hi Asaf,
If you select Addons > Messaging > Push and select to send a message to Everyone, then everyone who has your app installed will receive that message. You can also setup specific users inside Kinvey and then select 'Specific Users' and define the users you want to send the message to.
If you want to pass data from your own server to Kinvey or Parse to be sent as a notification, you can setup a custom endpoint.
Inside your Kinvey account, you would go to Business Logic->Custom Endpoint and define your custom endpoint, i.e. MyCustomMessage.
Then, on the KinveyProvider component, you would set the PushEndpoint property to the name you defined (i.e. MyCustomMessage) for the Custom Endpoint inside your Kinvey account.
Then, you need to setup some custom code for your Custom Endpoint inside your Kinvey account (Business Logic->Custom Endpoint), i.e.:
function onRequest(request, response, modules){
var iOSAps = request.body.iosaps;
var push = modules.push;
var iOSExtras = request.body.iosextras;
var androidPayload = request.body.androidpayload;
var androidmessage = androidPayload.message;
var message = request.body.message;
push.broadcastPayload(iOSAps, iOSExtras, androidPayload);
response.complete( 200 );
}
Regards,
Sarina -
Sarina DuPont, Product Manager RAD Studio » Visualizing json data with LiveBindings Thursday, 17 April 2014
[...] time I send a notification to my app (based on the instructions in this blog post), I will see the raw json data returned in my Memo. This is very useful for seeing what json you [...]
-
Sarina DuPont, Product Manager RAD Studio » Using Custom Endpoints to create a BaaS enabled Desktop application for sending notifications to your mobile apps Thursday, 17 April 2014
[...] to your mobile devices on iOS and Android. This blog post assumes that you followed the steps in my previous blog post and in the referenced docwiki [...]
-
Godfrey Fletcher Tuesday, 29 April 2014
Hi
Can you send a push notification to one device. I would like to send a message to one of my customer's cell phone. On receiving the message the customer must activate my app(which may not be running at the time)and respond by adding some information. Is this possible?
Thanks -
Sarina DuPont, Product Manager RAD Studio » Extend your mobile apps and increase user engagement with push triggers Wednesday, 30 April 2014
[...] I thought I would expand on my recent blog post that covered our new push notification support that we introduced in RAD Studio [...]
-
sarinadupont Wednesday, 30 April 2014
Hi Godfrey,
You can setup users inside your BaaS provider account and define a username and password for each user. You could then add a login screen to your mobile app, and if the user is logged in to their device, you could send a specific push notification to that user.
When you define your push notification message inside your BaaS provider account, you can define the user you want to send the message to.
Regards,
Sarina -
Agustin Seifert Wednesday, 30 April 2014
Hi!
I have to questions.
First, my app isnt running and the user just press one notification. How can I know which one was pressed? when the app is running pressing the notification fires again "PushReceive" event but when app isnt running not.
Second, how can I remove a notification from list?
Thanks in advice,
Regards! -
sarinadupont Monday, 5 May 2014
Hi Agustin,
TPushEvents has a property called StartupNotification. If the application was started when the user selected a notification, the StartupNotification property will contain the notification.
Regarding removing a notification from the list, that is something the user needs to do by swiping to the left inside notification center to delete the notification or clicking on the icon in the notification center to clear all notifications.
Regards,
Sarina -
Luigi Monday, 5 May 2014
put component notificationcenter...
procedure TForm1.PushEvents1PushReceived(Sender: TObject;
const AData: TPushData);
var Notifica:TNotification;
begin
Notifica:=NotificationCenter1.CreateNotification;
try
Notifica.EnableSound:=True;
Notifica.AlertBody:=AData.Message; NotificationCenter1.PresentNotification(Notifica);
finally
Notifica.DisposeOf;
end;
void __fastcall TForm1::PushEvents1PushReceived(TObject *Sender, const TPushData *AData)
{
TNotification * Notifica = NotificationCenter1->CreateNotification();
Notifica->EnableSound=true;
Notifica->AlertBody=AData->Message;
NotificationCenter1->PresentNotification(Notifica);
Notifica->DisposeOf;
the original example is from embarcadero help. i change only AData for alert body
Thank you Sarina for this tutorial -
Please login first in order for you to submit comments
RAD Studio XE6 is new software introduce in android devices this was very popular application among the people. I try to make this version for ios I took help from https://www.bestbritishwriter.com/ukessays-com-review/ because they have codes I did not know about all codes for this.