##GCM Sample Client and Server
sample code for Google Cloud Messaging for Android. The client is an Android app and the server is a PostMan Tool
##Setup Google Cloud Messaging At first, you need go to google developer console setup a project and enable Google Cloud Messaging API. And then create a server key, so you have two data.
- gcm sender ID (google developer console project ID)
- gcm server key
##Client The Android App can help you direct get push token.
- put sender ID in editText
- click
取得tokeb
button, and then token will show in the screen - click
mail
button send to your email
##Server
Use PostMan and import gcm-push.json.postman_coll
. Download here
######HTTP HEAD
Content-Type:application/json
Authorization:key=your gcm server key
######HTTP BODY
{
"to": "your Android devive push token",
"data": {
"message": "your message",
}
}
#####HTTP POST Request Sample
Use Token
push
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyC1bjpdS61qAQOAzDt281VZn8XTBdGQa3A
{
"to": "cHni_q-c6FQ:APA91bFXeCryQYvToMCMyCAHZuQJTK-yEK5a81FNqwIc6t40RCa54HBdxi-5g5shcWNNUmIxF3HaDl6IEl33XL1GBG1EgQFhzAUEcI5VNPO6hB72UJwrJ_I7O9JrTz_uR8qugbp5NBpn",
"data": {
"message": "推播token",
}
}
Use Topics
push
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyC1bjpdS61qAQOAzDt281VZn8XTBdGQa3A
{
"to": "/topics/foo-bar",
"data": {
"message": "推播topics",
}
}