B4A Library Push notification (Google C2DM) framework - BETA

Not open for further replies.
The updated files and tutorial are available here: http://www.b4x.com/forum/basic4andr...ush-notification-c2dm-framework-tutorial.html

Google provides a push service for Android. Using this service requires building several components. This framework simplifies the process of adding push notification support for your applications.

This is the first beta which should be considered a proof of concept. I think that the usage of this framework is surprisingly simple (compared to implementing all the required components yourself).

Next week the first version will be released together with a complete tutorial. For now you are more than welcomed to download and play with it. Later it will be easy to continue with the stable version.

The official documentation about C2DM service is available here: Android Cloud to Device Messaging Framework - Google Projects for Android
It is recommended to go over it.

The framework consists of three components:
- Client application which includes the code required for registering the device and handling the messages. This is the code that will be integrated in your application.
- Desktop command line tool that sends the messages.

- A php script that manages the registrations. Currently the desktop and device programs are configured to use the script hosted on this site. The script itself will be included in the stable release.

How to configure this framework
First you need to register with Google: Sign Up for Android Cloud to Device Messaging - Google Projects for Android
Remember the package name you provided to Google as you will need it later.
From my short experience it took a couple of hours till my account was approved.

Unzip the desktop component and edit config.txt.
You should enter the mail address you provided and the account password.
[email protected]
Unzip and open the B4A program.
Update the two following fields in Sub Process_Globals in the main activity:
    Package = ""
    SenderId = ""
Package is your application package name. It should be the same as the name provided when you sign up. You should also set the application package name by choosing Project - Package name.
SenderId is the mail address (ex: [email protected]).

Edit AndroidManifest.xml (located in Objects folder) with a text editor and replace all occurrences of: anywheresoftware.b4a.samples.push with your package name.

Run the client application
Enter a unique name and press Register. You will later use this name to send messages to this device. A good name can be your forum user name.

After a few seconds you should see a toast message saying that registration was successful or an error message. The message should also appear in the logs.

If registration was successful then it's time to send some messages...
Go to the folder of the desktop component and open a command window (in Windows 7 and Vista it can be done by pressing shift together with right click on the folder icon).

Now run b4a_c2dm.bat with the following arguments:
send <device name> <message>

The device should show a toast window with this message. Note that it doesn't matter whether the program runs or not.

Questions and feedback are welcomed...


  • Desktop.zip
    6.3 KB · Views: 374
  • Device.zip
    7.1 KB · Views: 366


Well-Known Member
Licensed User
Longtime User
Great addition.

Is Android 2.2 a minimum requirement for C2DM?


Active Member
Licensed User
Longtime User
So essentially this is a way to send a message to many android apps from the PC?


Well-Known Member
Licensed User
Longtime User
Plans to replace the desktop app. with a PHP sample? Practically seen that is probably the most used scenario.


Active Member
Licensed User
Longtime User
I guess we could script-in IFs which would check if such a message have arriven, and do something?

You don't need to. The device, once registered via the app is always listening to the Google Server for a message. This is handled in the example code service module by the sub :

Sub MessageArrived (Intent As Intent)

end sub

The Intent.GetExtra("data") is the message body that is sent to the device.

When your server sends a message to the Google server, it checks the Device ID and then sends it to the Device.

I have been running the Google Push service on my device for nearly three weeks and noticed no noticeable extra battery usage. As for send speed, I can say it is almost instantaneous.

There is a limit on the size of the message you can send, from what I have read the service is designed to send a small message that the device can then act upon, for example get an update from your own server. The way I am using it in my app is to send a single character to the device, then depending on that character perform different tasks.

Last edited:


Licensed User
Longtime User
This is great - I noticed it a couple of days ago and then on here!! :)

C2DM imposes the following limitations:

•The message size limit is 1024 bytes.
•Google limits the number of messages a sender sends in aggregate, and the number of messages a sender sends to a specific device. Please refer to the section on quotas for more information.

It opens up a number of possibilities :)


Active Member
Licensed User
Longtime User
Hi, I can not open the desktop version. It always appears the following error. Why is that?

Not open for further replies.