In RAD Studio XE6, we introduced support for remote push notifications with our BaaS (Backend as a Service) integration. We include components for Kinvey and Parse, two popular BaaS providers, right out of the box.



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:




C++

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:

  1. Copy:

    • the Project ID from your Google Cloud Messaging Setup

  2. the API Key from your Google Cloud Messaging Setup


CCG Configuration.png


To enable GCM support in an Android application, you will need to include some additional entries in the AndroidManifest.xml for the project. When you build your project, RAD Studio uses AndroidManifest.template.xml as a template to generate AndroidManifest.xml in the output directory.

You will need to edit the template file which lives in the same folder as your project. You can access it in your project folder (i.e. C:/MyPushDemo) after you have built the project. The entries you need to add are described here.

Now I am going to hit Run in the IDE to deploy the application to my Nexus 10.

To send the push notification to my app, I just had to click on Addons > Messaging > Push and select 'Send a Push'.



Sarina
Anonymous
  • 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 www.bestbritishwriter.com/.../ because they have codes I did not know about all codes for this.
  • Hi. Where to find information about remote push notifications on ios with RAD and kinvey? In IOS project got "DeviceToken request falled". C++ Builder Berlin update 2.
  • >If I debug my app 15 times and deploy it to my Android tablet, then I will get 15 copies of my notification. I have the exact same problem with kinvey! How to fix? Thank you.
  • 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
  • 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
  • Hey Sarina! Caroline from Kinvey here. I found your blog because a bunch of people have been following your tutorial and asking about it on our community forums. This is super awesome. Thanks for making this tutorial!
  • [...] Remote Push Notifications [...]
  • Hi Hendrik, I don't know much about your Android device, but to verify whether your Android device supports GCM (Google Cloud Messaging), please see developer.android.com/.../gcm.html Are you using the TPushEvents component as well? In addition, you need to make sure to first set up the user inside your Kinvey account and then fill in the username/password on the component. The Kinvey MasterSecret is shown inside your Kinvey account. Make sure that the MasterSecret/AppKey/AppSecret are from the same app you set up inside your Kinvey account in case you have several ones set up. Regards, Sarina
  • Hi Sarina, I used a ShowMessage() procedure to display the PushEvents1DeviceTokenRequestFailed event. It says something to the effect of SERVICE_NOT_AVAIL. Does this perhaps mean that (since we know Kinvey is not faulty), that my Android device might not be supporting Delphi/Kinvey Push Notifications? I have a Samsung SG-5301, fairly new still...
  • Hi Sarina, I am just not winning here. Are we sure the TKinveyProvider is functional in Delphi XE6 Enterprise? Maybe I should have purchased a larger version? I set up the Google GCM and inserted the AppID (ProjectID??) and the Secrets, MasterSecrets (is this maybe a secret, which is why I can't get it to work?), user names and passwords. Still nothing. If the Manifest has been set up (pretty much verbatim) according to the given tutorial and I follow your tutorial also pretty much exactly, then surely I should/could expect notifications to reach my mobile device? Is there a way I can post my code/xml so that you can have a look and see if I messed up somewhere? This post does not allow pasted code, unfortunately.
  • Hi Hendrik, I don't see the manifest file code in your blog comment. Did you have a look at docwiki.embarcadero.com/.../Creating_the_Application Regards, Sarina
  • Hi Sarina, I can't seem to get this to work on Android. On iOS I have no issues, but Android just nothing. I followed the tutorial (including Google & Apple account set ups) exactly and made all the required changes to my manifest. This is my Manifest file, did I mess something up?
  • Hi Sarina Thank you for your reply! No, i only use one App with this Key. i think the Problem was by Kinvey. I Just deleted all Users and create new ones. Then it works. Don't know why :P But thank you very much anyway! Best regards!
  • Hi Sarina , Thank You for you replay. On iOS all is working properly but i do not use the parse/kinvey metod. the problem is on Android 4.2.2 /4.4.2 when my application is closed the notification arrive in the notification area but no vibration and no sound. Regards Beppe
  • Hi Giuseppe, Regarding sound files on iOS for push notifications, I would recommend looking at this URL: developer.apple.com/.../IPhoneOSClientImp.html The sound property identifies a sound file in the app bundle. Regards, Sarina