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 :)

    thanks!
     
  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?
    Thanks
     
  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 C2DM.java 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 C2DM.java 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 ?

    Palmzac
     
  15. TsubasaOzora9

    TsubasaOzora9 Banned

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

    thanks.
     

    Attached Files:

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

    rbsoft Active Member Licensed User

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

    Rolf
     
  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 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
    database.
    at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:67)
    at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:218)

    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";
    $devicepassword="aaaaaaaaaa";
    $serverpassword="aaaaaaaaaaa";

    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?

    Thanks!
     
  19. Marcos Alves

    Marcos Alves Member Licensed User

    Hi again Erel,

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

    ?

    $databasehost = "localhost";
    $databasename = "";
    $databaseusername ="";
    $databasepassword = "";
    $devicepassword="34f34fkj02d3";
    $serverpassword="9034f3po4gj34";

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

    Fix this script for:

    ?php

    $databasehost = 'localhost';
    $databasename = '';
    $databaseusername ='';
    $databasepassword = '';
    $devicepassword='34f34fkj02d3';
    $serverpassword='9034f3po4gj34';


    Worked!

    Thanks!
     
  20. Avansys

    Avansys Member Licensed User

    Hi,

    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: java.io.IOException: Server returned HTTP response c
    ode: 401 for URL: https://android.googleapis.com/gcm/send
    at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:57)
    at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:218)

    But, I configured all files:

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

    board_url=http://b4aserver.basic4ppc.com/c2dm_board.php
    server_password=9034f3po4gj34
    api_key=AIzaSyAfuQ93b_hq7XIeWdbSF-efd0sbdlplbWQ <- this is an api key for Android apps, I got it with this BB:xxxx...xxx:75;anywheresoftware.b4a.samples.push

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

    'Activity module
    Sub Process_Globals
    Public DeviceBoardPassword, BoardUrl, SenderId, DeviceName As String
    DeviceBoardPassword = "34f34fkj02d3"
    BoardUrl = "http://b4aserver.basic4ppc.com/c2dm_board.php"
    'Set this field to match the project ID in Google Console.
    SenderId = "530122475530"
    End Sub


    I looked for these server responses at the link http://developer.android.com/intl/fr/guide/google/gcm/gcm.html#response, but I didn't find nothing

    Somebody who can help me? thanks
     
Loading...