Android Tutorial Android push notification (GCM) framework and tutorial

Discussion in 'Tutorials & Examples' started by Erel, Jul 3, 2012.

  1. Erel

    Erel Administrator Staff Member Licensed User

    I wouldn't use these messages to actually send the data. Instead you can notify the devices that they need to be updated and then use the regular HTTP based methods to make the update.
  2. sorex

    sorex Expert Licensed User

    indeed, that saves a lot of requests aswell. didn't think that far yet :)

  3. mc73

    mc73 Well-Known Member Licensed User

    I'm successfully using this aproach, still I wonder if this can work for more than 20 devices, if of course I understood the documentation. If this is really a limit, are there any alternatives at the moment?
  4. Erel

    Erel Administrator Staff Member Licensed User

    Where is it stated that it is limited to 20 device?
  5. wizard699

    wizard699 Member Licensed User

    Hi Erel.
    But this Push example is valid? There is something linked to HTTP library that make crash the app.
    Something with Response.GetString.
    There is a version of Push client using HTTPUtils?
  6. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the Device project to use HttpUtils2.
  7. pesquera

    pesquera Active Member Licensed User

    Hi, I want to send push messages with my App, like the util b4a_gcm.bat does. How can I include the source into my Basic4Andriod Project?
    Thanks in advance
  8. dealsmonkey

    dealsmonkey Active Member Licensed User

    At the beginning of this thread are the instructions and library files to add to your B4A Project. You will then need a way to push the message to the the devices, this can be a web based server, a desktop program etc..
  9. pesquera

    pesquera Active Member Licensed User

    thanks for your response dealsmonkey, I already did that.. but, I need to push messages with mi Android's App instead of desktop.. I'm new with B4A & java.. sorry if my question is so trivial.. The source posted by Erel is for include it into a B4a Project, isn't it?
  10. dealsmonkey

    dealsmonkey Active Member Licensed User

    Yes the source is to include for receiving a push. It will be easier to have a web based server to send the messages. Have a look at the link in my signature. This service is not fully complete but getting there, I have been delayed doing a large app for a client, but that is nearly done, so should finish up the server asap :)
  11. pesquera

    pesquera Active Member Licensed User

    your site looks great! but, I need to send push messages with my android application (B4A) instead of a web server or desktop.. is it possible to do?
    Last edited: Aug 10, 2013
  12. dealsmonkey

    dealsmonkey Active Member Licensed User

    Yes, You send your message from your app via our servers via a simple http Post. You need a 3rd party server to hold to registration details of all the devices registered with your app.

    I will have a message with Erel and if he is ok with it, will post some sample B4A code
  13. pesquera

    pesquera Active Member Licensed User

    great! thank you dealsmonkey, it will be very helpful
  14. palmzac

    palmzac Active Member Licensed User

    Hi Erel,

    Thank for your good library ! Everything work find. ^_^ Would you write a PHP code for sending message ?

  15. TsubasaOzora9

    TsubasaOzora9 Banned

    Hi erel, how to make the notification bigger like in my attachment.


    Attached Files:

    • eee.png
      File size:
      20.5 KB
  16. rbsoft

    rbsoft Active Member Licensed User

    That would be very interesting. I am looking forward to it.

  17. dealsmonkey

    dealsmonkey Active Member Licensed User

    Hi guys, I've been a little busy finishing a project for a client, holidays etc. I have spoken to Erel and he is happy for me to post some info and examples, so I will do this is in the coming week :)
    rbsoft likes this.
  18. Marcos Alves

    Marcos Alves Active Member Licensed User

    Hi Erel,

    I installed my own GCm server in an Amazon windows instance, running php 5.3 and Apache 2.2 with mysql. But a very strange behavior is happening. I changed the B4A push app pointer to my server and password and, when I try to register, I receive a message registered in the emulator. But when I try to send a message I receive an error:

    C:\GCM>java -cp b4a_gcm.jar anywheresoftware.b4a.c2dm.C2DM send mmalves "ok vivo
    java.lang.RuntimeException: Error=InvalidRegistration,name=mmalves removed from
    at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(
    at anywheresoftware.b4a.c2dm.C2DM.main(

    When I search the table c2dm which sould have been created by php script, surprise! There is no table in mysql database! I thought that if I received a registration sucessfull that means that the cicle including google GCM registration AND table line include (or table create) was complete... but not.
    What is happenig? Could you help me?
    My connection in php script is:

    $databasehost = "localhost";
    $databasename = "anonme";
    $databaseusername ="anonme";
    $databasepassword = "xxxxxxxxxxx";

    Device password and server password are according to google and config.txt respectivelly. This looks that database is not being connected by php script, but why do I receive register sucessfull message in AVD?

  19. Marcos Alves

    Marcos Alves Active Member Licensed User

    Hi again Erel,

    Fixed! The problem was the webserver php script attached to tutorial. Look at:


    $databasehost = "localhost";
    $databasename = "";
    $databaseusername ="";
    $databasepassword = "";

    1. Missing php "word" at start (should be ?php )
    2. Using " instead of ' ...

    Fix this script for:


    $databasehost = 'localhost';
    $databasename = '';
    $databaseusername ='';
    $databasepassword = '';


  20. Avansys

    Avansys Member Licensed User


    I have a problem, when I send a message the server response is this:

    java -cp b4a_gcm.jar anywheresoftware.b4a.c2dm.C2DM send avansyst "test"
    java.lang.RuntimeException: Server returned HTTP response c
    ode: 401 for URL:
    at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(
    at anywheresoftware.b4a.c2dm.C2DM.main(

    But, I configured all files:

    ************ config.txt ***************

    api_key=AIzaSyAfuQ93b_hq7XIeWdbSF-efd0sbdlplbWQ <- this is an api key for Android apps, I got it with this;anywheresoftware.b4a.samples.push

    ************ PushExample.b4a **********

    'Activity module
    Sub Process_Globals
    Public DeviceBoardPassword, BoardUrl, SenderId, DeviceName As String
    DeviceBoardPassword = "34f34fkj02d3"
    BoardUrl = ""
    'Set this field to match the project ID in Google Console.
    SenderId = "530122475530"
    End Sub

    I looked for these server responses at the link, but I didn't find nothing

    Somebody who can help me? thanks