AutoRemote Google Cloud Message direct push to Autoremote

Discussion in 'Guides / Examples / Ideas Forum' started by IanB, Sep 21, 2016.

  1. IanB

    IanB New Member

    Joined:
    Sep 21, 2016
    Messages:
    3
    Likes Received:
    0
    I need to use Google Cloud Messaging directly from a web server to push messages to an Android device running Autoremote (or Join whichever is better). I can send push messages using the https://autoremotejoaomgcd.appspot.com/sendmessage?key=........... URL but this of course uses the Autoremote server. I need to achieve this functionality using Google Cloud Messaging directly and not using any server other than the Google Cloud Messaging and I'm looking for some example code that will point me in the right direction (maybe PHP code but any language will do so I can see how it works).

    Thanks.
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Already replied via email :)
     
  3. Pedro Melim

    Pedro Melim New Member

    Joined:
    Oct 12, 2016
    Messages:
    1
    Likes Received:
    0
    Building an app with some friends atm, and one of the things we are looking it its something similar, any chance you could let me know how its done?
     
  4. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Ok, here's a javascript version for Join (not AutoRemote). Let me know if you have any questions about it (replace uppercase stuff with your own values):

    Code (Text):

               var req = new XMLHttpRequest();
               req.open("POST", "[URL]https://gcm-http.googleapis.com/gcm/send[/URL]", true);
               req.setRequestHeader("Authorization", "key=AIzaSyDvDS_KGPYTBrCG7tppCyq9P3_iVju9UkA");
               req.setRequestHeader("Content-Type", "application/json; charset=UTF-8");

               var contentString = "{"data":{"json":"{\"push\":{\"title\":\"Note To Self\",\"text\":\"hello\",\"deviceId\":\"YOUR_DEVICE_ID\",\"senderId\":\"YOUR_SENDER_DEVICE_ID\",\"id\":\"ANY_UNIQUE_ID\"}}","type":"GCMPush"},"registration_ids":["YOUR_REG_ID"],"priority":"high","delay_while_idle":false}";
                        req.send(contentString);
     
    To get your device IDs and reg IDs list your devices with the List Devices API found here: http://joaoapps.com/join/api/

    Hope this helps!
     

Share This Page