In Appmethod, we provide support for remote push notifications via our BaaS (Backend as a Service) integration.
We include components for Kinvey and Parse, two popular BaaS providers, right out of the box.
In this tutorial, I am going to show you how to setup and enable push notifications in your applications using Appmethod. The 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 Appmethod 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;
procedure TForm1.PushEvents1PushReceived(Sender: TObject;
const AData: TPushData);
ListView1.Items.Add.Text = AData.Message;
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:
the Project ID from your Google Cloud Messaging Setup
the API Key from your Google Cloud Messaging Setup
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, Appmethod 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’.