Android Tutorial Android push notification (GCM) framework and tutorial

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

  1. Tiby

    Tiby Member Licensed User

    Hello, I did everything as the tutorial and I can send the message and get a OK result but I do not receive any message. Why?
    Thank you
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Is the device application installed? Have you checked the logs?
     
  3. abay1968

    abay1968 Member Licensed User

    How to send message to all registered device?
     
  4. bloxa69

    bloxa69 Active Member Licensed User

    I played with the demo and it works for me without any glitches, great library.
    I noticed though when you uninstall the app the device itself stays registered and Google keeps sending the messages to the device, but they just don't show up of course. I know one could unregister on pause and reregister on resume, but in my case it will not work as I need to send messages even if the app is in bg or closed.
    My question is, is it possible to check somehow before sending push notification (over GCM or any other way) if the app is still installed and if it's not, remove the registered device that doesn't have your app anymore from the list? Otherwise the list of registered devices will collect a lot of garbage registrations over the time and that would be some serious waste of resources, sending the push notifications to those "ghost" devices that will never receive them.

    Thanks
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can use GetAll command to get a list of all the registered devices. You can create a batch program that reads the result and send a message to each one of the devices.

    bloxa69, you will not be notified in that case. You can modify the PHP script and add a time stamp to each device.
    Each time that your program starts it should contact the server and reregister the device.
    You can then remove devices that haven't registered in the last x weeks / days.
     
  6. abay1968

    abay1968 Member Licensed User

    Thanks for your response.
     
  7. bloxa69

    bloxa69 Active Member Licensed User

    Erel, thanks for advice. I did it in slightly different way but in your direction, works for me now.
    :sign0013: but I got another question already:

    Let's say I have 3 of my apps installed on the same device. I send push messages to all of them. I can avoid multiple notifications by specifying the same notification number, like n.Notify(1). What about the toast message - how to avoid multiple toast messages from all those 3 apps and display it just ones?

    By the way, I saw people asking how to send to all devices in other posts as well. This is the little batch file I got working on Win 8 (put it in the same folder as b4a_gcm.bat and make sure no folder names in the path have spaces, otherwise it will choke):
    Code:
    REM @ECHO OFF
    REM Uncomment @ECHO OFF 
    if detailed output is not needed

    For /F %%a IN ('call b4a_gcm.bat GetAll') Do call b4a_gcm send %%a %*
    Then run command:

    Code:
    YourSendToAll.bat "your message"
     
    Kwame Twum and Pintinho like this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    Thank you for sharing the batch file.

    It will not work. Each notification is specific to a single app. You will get three icons.

    Do you have three ids for each device?
     
  9. MarkNZ

    MarkNZ New Member Licensed User

    Unable to start service Intent

    Hi

    I have downloaded the supplied example GCM code, changed the sender ID as required.
    Using a Virtual Device, when I click the register button I get no action but the following in the device log.

    "Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTER (has extras) }: not found"

    I have tried it with a three virtual devices, one running android Ver 4.1.2 , another with Ver 4.2 with the same result, a third with 2.3.3.

    I can't seem to find anything on the web that points me to the problem.
    Any suggestions?
     
  10. MarkNZ

    MarkNZ New Member Licensed User

    The answer seems to be that the virtual devices I had created targeted the Android API.
    When I created one targeting the Google API all works!!

    I am very happy now.
     
  11. priceverynice

    priceverynice Member Licensed User

    Nice tutorial Erel. All work fine, but is possible send push message from a app created with b4a without using b4a_gcm.jar?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Technically it is possible. You will need to reimplement the desktop tool.
    If you like I can post the Java code of this tool.
     
  13. priceverynice

    priceverynice Member Licensed User

    Yes, I like! If you can, post java code, or better a example in B4A. :D
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Java code is attached.
     

    Attached Files:

  15. marcick

    marcick Well-Known Member Licensed User

    Is there any limit of use of this service ?
    Can I for example send a message every 30 seconds to 5 devices ?
    I'm looking for a solution to have a real time (one way) communication between a server (or also a b4a app) and several devices.
    Marco.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    The official documentation is available here: GCM Advanced Topics | Android Developers

    Yes (as far as I understand from their documentation).
     
  17. marcick

    marcick Well-Known Member Licensed User

    Thanks.
    It's difficult for me to understand this, but seems some limits exists.

    I need to be sure that messages are received, every 30 seconds, all day long.
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    The actual limits are not specified. I recommend you to do some tests.
     
  19. marcick

    marcick Well-Known Member Licensed User

    Thanks again.
    Excellent guide. Everything works fine on my server also. Superb.

    Now I have to think how to generate the notifications from a VB.NET application.
    Yes, I can call a command line from VB.NET, but I think there should be a more elegant solution. Do you have any idea ?
    Marco
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    I recommend you to start with a "shell" solution. Otherwise you will need to reimplement the Java tool in your code.
     
Loading...