Monday, June 27, 2016

Source code to Implement push notification for Sending and Receive messages via GCM for Android Studio

GCM Model Diagram


Send a message using GCM HTTP connection server protocol:



  https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
    "to": "/topics/foo-bar",
    "data": {
      "message": "This is a GCM Topic Message!",
     }
  }
Handle a downstream message on an Android device:


  @Override
  public void onMessageReceived(String from, Bundle data) {
     String message = data.getString("message");
     Log.d(TAG, "From: " + from);
     Log.d(TAG, "Message: " + message);
     // Handle received message here.
  }

No comments:

Post a Comment