{"__v":0,"_id":"5581f2958625220d00429ee1","category":{"__v":3,"_id":"555f9e9ed7777119003acfee","pages":["555f9fcfd7777119003acff8","555fa01d336c041700a9b832","5581f2958625220d00429ee1"],"project":"555f9bf814d68e0d00966587","version":"555f9bf814d68e0d0096658a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-22T21:24:46.312Z","from_sync":false,"order":5,"slug":"gcm","title":"GCM"},"parentDoc":null,"project":"555f9bf814d68e0d00966587","user":"555f9a010758330d000d531a","version":{"__v":9,"_id":"555f9bf814d68e0d0096658a","project":"555f9bf814d68e0d00966587","createdAt":"2015-05-22T21:13:28.470Z","releaseDate":"2015-05-22T21:13:28.470Z","categories":["555f9bf814d68e0d0096658b","555f9e9ed7777119003acfee","555fa040d7777119003acffd","555fa344d7777119003ad00b","555fa3e6d7777119003ad00f","555fb694336c041700a9b86e","555fb779336c041700a9b86f","555fb86bd7777119003ad039","555fbf1a336c041700a9b87f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-06-17T22:20:05.842Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"Receiving messages is done by implementing [a basic GCM receiver](https://developers.google.com/cloud-messaging/android/client#sample-receive). If the flag `encrypted` is set to `true` then the message must be decrypted using the device's private key first. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\npublic void onMessageReceived(String from, Bundle data) {\\n  JSONObject pushMessage = new JSONObject(data.getString(\\\"message\\\"));\\n  if(data.getBoolean(\\\"encrypted\\\", false)) {\\n    // Decrypt the message \\n  }\\n  \\n  // Parse message, this should be in the standard \\\"message\\\" \\n  // object format.\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"receiving-messages","type":"basic","title":"Receiving messages"}

Receiving messages


Receiving messages is done by implementing [a basic GCM receiver](https://developers.google.com/cloud-messaging/android/client#sample-receive). If the flag `encrypted` is set to `true` then the message must be decrypted using the device's private key first. [block:code] { "codes": [ { "code": "@Override\npublic void onMessageReceived(String from, Bundle data) {\n JSONObject pushMessage = new JSONObject(data.getString(\"message\"));\n if(data.getBoolean(\"encrypted\", false)) {\n // Decrypt the message \n }\n \n // Parse message, this should be in the standard \"message\" \n // object format.\n}", "language": "java" } ] } [/block]