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

    401 means that there was an authentication problem. Your api_key is probably wrong.
     
  2. Marcos Alves

    Marcos Alves Member Licensed User

    Hi Erel,

    I´m using Google Cloud Message to implement an application and read that there are two ways to send a message: collapse and non collapse. The difference between this two methods is the way used by google server in the queue. In collapse method server maintains only the most recent message to each client. This is adequated to send message without paylod (ex: new email messages), which only start a proccess in client. The second method (non collapse) is used for messages with payload and when used means that , even the device is off line when server sends the messages, each one will be delivered (limited to 100 or 4 weeks) - information fromhttp://developer.android.com/google/gcm/adv.html .
    Using your java client (server side) I realized that you use the collapse method and there is no parameter in configuration file to change this.
    So PLEASE, could you compile a new java GCM send api (.jar) whith external option to choose between collapse or non collapse keys (or share/send java source to give the possibility to change this flag?)

    Thanks!

    Marcos Alves
     
  3. Marcos Alves

    Marcos Alves Member Licensed User

    Erel,

    any answer ?

    Thanks
     
  4. Avansys

    Avansys Member Licensed User

    Hey Erel, thanks for that answer, I found the problem, the api_key was wrong, I read all replies and I found that the api_key isn´t an android key, but a browser key.

    Thanks again.
     
  5. Avansys

    Avansys Member Licensed User

    Hi Erel, one more question,
    What roles do the DeviceBoardPassword, DeviceName and ServerPassword variables?
    Thanks for your help
     
  6. DonManfred

    DonManfred Expert Licensed User

    Users of the Code need to use the correct Devicepassword to register their Device to your Database.
    Users of the Code need to use the correct DevicePassword AND ServerPassword to unregister itself from your Database.
    Those two are a securityhelp to Secure YOUR Database. >our PHP-Script will decline requeste where the wrong passwords are used.

    Devicename itself should be a unique name your user can register. You must look out that your users dont register a already exiting user. You should have a look at it cause when you want to send a push-notification you say google a "Devicename" who which the notif should be send.

    Hope my answer helps and i did not give a wrong answer :)
     
  7. Marcos Alves

    Marcos Alves Member Licensed User

    Hi Erel,

    any answer about collapse/no collapse flags in jar application?
     
  8. Avansys

    Avansys Member Licensed User

    Thanks for that info :)
     
  9. Malky

    Malky Active Member Licensed User

    I Get a message saying 'java' is not recognised as an internal or external command, operable program or Batch file.

    I would assume it's something to do with a path for java or something?

    Any ideas? I've used this machine for ages and not had this.

    Malky
     
  10. Marcos Alves

    Marcos Alves Member Licensed User

    Hi Erel,

    Wow, I think that this is the response for collapse pameter = yes in the jar application. But, just IF we want to send messages with payload... can you add an external parameter (in config.tet for example) to allow that?
    By the way, Erel, why do you think that these messages are not good to send data? I´m questioning because using the GCM I realized some "message loss" and "delays" in some cases (undesired in any messenger app off course.). What´s your feeling about GCM reliability?

    Thanks!
     
  11. Malky

    Malky Active Member Licensed User

    Fixed the java stuff, had an error which I fixed and now send a message and get a 'success IDxxxxxxx' message. Nothing appears on the phone?

    Any ideas please?

    Malky
     
  12. Malky

    Malky Active Member Licensed User

    Cancel, have it working now. Is there a way to get it to make a sound or something like normal notifications?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Note to all, it is better to start new threads for your questions. It is quite difficult to follow this one...

    About the collapse_key, have you tried to pass an empty string to it? Does it behave as if there is a collapse key defined?

    I can't say much about GCM reliability as I haven't stress tested it.
     
  14. Marcos Alves

    Marcos Alves Member Licensed User

    Hi Erel,
    answering your questions, we are developing a messenger system and I´m doing many stress tests. My feeling is: some messages eventually disapear and, as we don´t have a "google console" to trace, it´s very difficult to understand if that´s because some interaction betweeen network protocol and fail or any unknown issue of endpoints requests (server/clients, including android system).
    About advantages, we think that the greatest is change regular data/internet messages (events) from app´s to "intent status", like sms. This allow us to make an app which have the same behavior of a traditional sms interaction (if we have data connection, off course). BUT in my stress tests I realized that we are not free of doing some http pooling to recover "lost" update messages from gcm (this loos occurs frequently).
    About collapse key, I´m secure to tell you that it is ENABLED in java (.jar) client (in our tests, if the client is off line, ALWAYS only the LAST message arrives when connecting later - sometimes no one arrives!). I started to develop a new .jar with external configuration BUT stopped because KISS behavior which some friends used to tell me when working (KISS = Keep It Simple... :) ) . Considering that GCM reliability isn´t good and I could spend a lot of time to develop the new .jar, it´s easier to use this only as an aditional sync method and go to develop other pieces of app... but IF you have the .jar source you could easily add the collapse=yes/no paremeter in config.txt.

    That´s it!

    Thanks for reply.
     
    Last edited: Sep 29, 2013
  15. Erel

    Erel Administrator Staff Member Licensed User

    I see. I agree that it is better to use GCM only to notify the device that there is new data available. You can pass a random string as the collapse key to avoid the collapse key behavior.
     
  16. Malky

    Malky Active Member Licensed User

    Ok, tried to use the android id of the phone as a registration for this in my server Database, but keep getting an java error in httpjob?

    req.InitializeGet(sb.ToString) is the problem line

    Code:
    Dim objPhone As Phone
      
    id = objPhone.GetSettings("android_id")
      Register(
    id)
    java.lang.IllegalArgumentException: Illegal character in query at index 73: http://www.homersparadise.com/c2dm_board.php?device_password=34f34fkj02d3 & name= & id=APA91bFutoYt5j9aZOsm2hn_CLOyGAZBS98PoSeFmS-Fn0v0VJNawH3Q6tdh3wUL7MhpswXWvbo8yXjRIrf6pK6226O_BAOSzzLwT1dzJjHwShNXaLTxSfM3OdPuAKqwq08TH8gyKqILBBJCWRuRv3FwiqEgDsat1Q

    Any ideas please?

    Malky
     
    Last edited: Sep 29, 2013
  17. Erel

    Erel Administrator Staff Member Licensed User

    The name looks empty. This error message means that there is a character in the query that needs to be escaped. Check which character is in index 73.
     
  18. Marcos Alves

    Marcos Alves Member Licensed User

    Where Can I pass this random string - in .jar parameters? Please, could you give me a sample of a comand line ? (only curiosity because I´m decided to use GCM #JUST# to start pooling service :) )
     
  19. Malky

    Malky Active Member Licensed User

    Hi Erel, thanks for the reply?
    I did notice the name was empty and assumed the index 73 was line 73 in the supplied php file? As far as I am aware, the only difference between the push app and mine is setting the name to the Anrdoid id of the phone, rather than prompt the user for a name?

    Also, I have used the same credentials I used for the test with the supplied Push download and changed the url etc which works for me, but I had a friend test it and I get the username doesn't exist when I try to test the notifications?

    Do I have to change anything in the command line to send the notification as it still points to send NAME anywheresoftware.b4a etc?

    Cheers,

    Malky EDIT, I am not sure what this index 73 is if it's not the line?
     
    Last edited: Sep 29, 2013
  20. Malky

    Malky Active Member Licensed User

    I eventually found out what you were pointing at and there is a space in the url at index 17 after the name (which is originally sent in the first java error)!

    I used the replace function on the 'id' variable before calling register and I still get the same error?

    It seems like the call is being made several times or something? Or maybe I've just lost the plot?

    Malky
     
Loading...