How do I use Push Notifications with Android?

This lesson describes how to set up Push Notifications for Android Devices.

Screen captures and a sample stack are provided.

You can download the sample stack from this url:


Push Notifications allow you to send notifications from a server directly to an Android device. This reduces network bandwidth for applications that may normally poll a server at intervals, in order to receive an update on information the user may be waiting for.

Although Push Notifications are convenient and reduce network traffic, they are not supported by every service, both on the server side and the application side.

In order to set up Push Notifications, it is necessary that the devices register with the server. The server needs information on what device the notification is to be sent to. The device also needs to be able to receive the notification and act upon it.

This lesson is structured into the following three logical sections:

1. Signing up for Android Push Notifications

2. Writing a LiveCode Application with Push Notification Support

3. Sending a Push Notification

Signing up for Android Push Notifications (Cloud to Device Messaging)

Create a new project with the google api's console at the following website (N.B. you will need to sign in with a Google Account ID to create a project)

Give a name to your new project and click "Create"

Click in the "Products & Services" hamburger icon

Then choose "APIs & Services" and then "Library"

Search for "Google Cloud Messaging" and click on the first result, as shown above.

Now click on the "ENABLE" button

Creating the API Key for Access

Next, click on the "Credentials" option in the left pane.

Next, click on the "Create Credentials" button, as shown above.

Choose "API Key" in the dropdown menu

You have now created the API Key. Click on "Copy" and paste the API Key to a safe place. I have hidden the last part of my key for security.

Select the "Key restriction" level, and click on "Save". For simplicity I have selected "None", but it is suggested to add a restriction level.

Click on the hamburger icon (1), then select "IAM & admin" from the dropdown (2), and then "Settings" (3).

Write down the "Project Number". This will be used in the Standalone Application Settings for Android, in the field "Push Sender ID".

Enabling the LiveCode Stack for Push Notification Support

Go to Standalone Application Settings for Android, and in the field "Push Sender ID", fill in the "Project Number" you wrote down in the previous step. Moreover, make sure you have enabled the "Internet" permission.

Writing a LiveCode Application with Push Notification Support

Writing a LiveCode Application with Push Notification Support

When you have registered with GCM and activate the service you can create a LiveCode stack that tries to register with the Push Notification Server. Add the following code to the LiveCode stack script:

on pushNotificationRegistered pMessage
   answer "Registered:" && quote & pMessage & quote with "Okay"
end pushNotificationRegistered

Once you start the application, you should receive a message that is similar to the one shown in this step. The token displayed is specific to your device and you need to record it, so that you can send to the device from an application or a server. In this test scenario you may want to e-mail the token to yourself, possibly by updating the code as follows:

on pushNotificationRegistered pMessage
   answer "Registered:" && quote & pMessage & quote with "Okay"
   // Update the e-mail address as required
   revMail "",,"token",pMessage
end pushNotificationRegistered


Sending a Push Notification (LiveCode)

Sending a Push Notification (LiveCode)

Using the sample stack provided with this lesson, you can send a Push Notification to the device.

The API Key is the key created in the step "Creating API Key for Access".

In the "Devices" field enter the token generated in the step "Writing a LiveCode Application with Push Notification Support".

Enter the "Message", the "Title" and the "Payload" that are to be delivered to the device. The message and title are displayed by the Android Operating system in different locations, depending on the version of the device and the activity of the application that is receiving the notification. The payload is delivered as a message to LiveCode.

What is in the Push Notification?

LiveCode uses the following fields to store and process push notification information.

data.body - The message body displayed in the status bar (default: "User interaction requested").

data.title - The title of the message displayed in the status bar (default: the app label).

data.badge_value - The badged number to display along with the statusbar message.

data.play_sound -  A Boolean that indicates whether or not a sound should be played when the notification is received (true / false).

data.payload - The message that is delivered to the app in its remoteAlert handler.

This information is needed when creating the notification you plan to send to an Android device.



This is out of date now

C2DM has been officially deprecated as of June 26, 2012.

What do we do now?

The cloud version seems much more of their api integrated.

How do livecode uses proceed now?

Hanson Schmidt-Cornelius

Hi Peter,

the LiveCode engine can operate without any changes when you migrate from C2DM to GCM. However, it is necessary to make some changes to your LiveCode application. You have to replace the current developer email address that is passed in the sender parameter of the registered intent with the project ID that is registered when signing up with GCM.

The server side also requires modifications, but these are also minor.

You can get more information on this topic by referring to:
In particular have a look under the headings "Client changes" and "Server changes".

Kind Regards,



It's not at all clear from this lesson how one acquires a registration ID for the android device. As far as I can understand from the lesson, Google's GCM service should simply respond with a registration ID if a Livecode app running on an android device contains a handler with this signature: "on pushNotificationRegistered tMessage".

I've built such an app and loaded into an android device, but nothing happens. If the client registration ID is acquired by some kind of magic, I doubt that it will work for GCM as it does for C2DM, since the service endpoints (URLs) have changed. On my device the pushNotificationRegistered message is not called, and I don't see from this lesson what could possibly trigger an action resulting in it being called.

I've also seen (e.g. on StackOverflow and on the Google Groups forums), that there is a lot of confusion amongst java developers, concerning the different IDs (server, browser, client) used for GCM, and particularly how to get the client registration ID.

So this lesson needs to be updated for GCM. Most of the instructions to be found in other resources assume that people are going to install additional elements to the android SDK, modify java files, install ant, and build the google-supplied GCM demo app in java, then load that onto their devices -- all in order to obtain a registration ID. That seems like an unnecessary excursion for Livecode developers.


I have got the pushNotificationRegistered message to trigger. The sender id (in the standalone application settings) needs to be the numeric project ID found in the URL of the Project page(s) in the Google API GCM console (something like "project:XXXXXXXXXXXX:access" in the URL when one is on the Google website, where the Xs represent the project's numeric ID required for the standalone settings).

I used the example in this lesson and emailed the client registration ID to myself, so that my server code could then address the individual devices in the GCM messages I was sending.


can we get push notification without using gcm and withour placing app in playstore?

i have a requirement to send notification/data to app user from our own webapplication . i know it is possible using google services but i want my application to send these maintanence to send notifications to android device is it possible iff please provide links regarding it,,thanks in advace

Hanson Schmidt-Cornelius

Hi Sampath,

you should not have to put your application into the android store in order to use push notification. That is basically what this lesson is doing. You will have to go through the GCM to set up your messaging, but this does not mean that you cannot send messages from your server. Have a look at the relevant android webpage for further information:

Kind Regards,


Daniel DuPont

It works great. I sent a push notice and it worked. But, how do I get the message received to open in the app? Right now, when I select the message it just vanishes from my notification area. Thanks!

Hanson Schmidt-Cornelius

Hi Daniel,

you have to handle the pushNotificationReceived message that is called once the push notification is received by your device.

Have a look at the local notifications lesson for a bit of information on how the application is launched and the message processed when a notification is received:

Kind Regards,


Daniel DuPont

Thanks Hanson. That issue is solved. Now I have to figure out why a second, or later, notice sent does not update if the app is still in the recent app list. If I remove the app from the recent app list it is fine. But that is not commonly done.

Hanson Schmidt-Cornelius

Hi Daniel,

thank you for your comment.

If the application is in the recent app list and it is suspended, then it is possible that the notification does not get received. We will investigate if this is something we can address.

Kind Regards,


Daniel DuPont

Hi Hanson,

Upon further testing, if the app is exited with the back button, it receives the next update. Only when exited with the home button is there an issue. If he app is cleared from recent apps, or is re-opened, exited with the back button, then re-opened it receives the update.

Hanson Schmidt-Cornelius

Hi Daniel,

thank you for the update. Yes, we were assuming that it had something to do with a particular state of the application. I have filed a bug report for development to look into the issue.

Kind Regards,



Hi, I tried to use your push notification sample but I couldn't figure out the Device ID prompted.

Any help on how to locate the Device ID? Thanks

Hanson Schmidt-Cornelius

Hi William,

Bernard had the same issue and discussed the issue slightly further up the list of comments. This should address the issue you are having.

Kind regards,


Ross Morrow

I used to use this lesson to work with Push Notifications. However, Google has now switched to a system called Firebase and I cannot get push notifications to work anymore with Livecode. Is there an update how to use Android Push Notifications with Livecode?

Elanor Buchanan

Dear Ross

This has been reported as an enhancement requested here

I think the most relevant part of the discussion there is that you can use FCM to send push notifications to LiveCode apps.

Hi all, thanks for your comments on this so far.

FCM itself is built upon the existing GCM messaging infrastructure so apps using GCM should continue to work.

It is also possible to use FCM to send push notifications to existing LiveCode apps with only a minor modification to the standalone settings, with no changes to the manifest required.

The process for setting up push notifications with FCM is somewhat different now though, as I will describe below:

1. log in to the Firebase console at
2. Create a new project for your app (or import an existing one if you already use GCM)
3. Click the settings icon and navigate to "Project Settings" then "CLOUD MESSAGING"
4. Replace the "Push Sender ID" in your app's Android standalone settings with the numeric "Sender ID" listed on that page.
5. Replace the server key you currently use to send push notifications with either of the "Server Key" or "Legacy Server Key" strings listed on that page.

You should now be able to send push notifications to your android apps once again.


There is some other information in the comments on the bug report that you might find useful.

I hope that helps.

Kind regards


Simon Schvartzman

Hi Elanor, after following the lesson I made this simple App (named Notification) which is able to register with Firebase Cloud Messenger.
When I use exactly the same code and same Push Sender ID on my "full" App, the same device does not register, as a matter of fact the "on pushNotificationRegistered..." is not even called.
I should mention that before running the full App I deleted the Notification App in order to avoid any conflict.
What am I doing wrong?
Any hint will be greatly appreciated. Regards

Elanor Buchanan

Hi Simon

I'm afraid it is very difficult to know what the issue might be. Have you checked that Push Sender ID and Internet permissions are correct in the Standalone Application Settings for your "full" App?

Kind regards


Simon Schvartzman

Hi Elanor, thanks for your reply. I know how difficult it is to identify the problem as I've been fighting with it for 2 days before posting here...
The Push Sender ID number is the same on both Standalone settings and the Internet Application Permission is also set on both Apps.
The Label and Identifier contents are different as you may expect.
I have also checked in the Android's App Notification permissions and both Apps are configured the same.
Is there anything else I should be checking for?
Could the problem somehow be related with Google Cloud Project Settings? One thing that is not clear to me is where do I "connect" the Google Cloud Project with my App? In other words as the Push Sender ID seems to be the only "link" between the two it seems that I could potentially have 2 or more Apps receiving the same Notifications which doesn't seem to make sense. I have the feeling this is where I'm doing something wrong.

Simon Schvartzman

Hi Elanor, I found the problem (still need help to find the solution) and reported it on the forum:

Elanor Buchanan

Hi Simon

I see you have added a comment to an older bug, I'll flag it with the team to be looked at.


Add your comment

E-Mail me when someone replies to this comment