{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Receiving messages","type":"basic","slug":"receiving-messages","excerpt":"","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]","updates":[],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5581f2958625220d00429ee1","category":{"sync":{"isSync":false,"url":""},"pages":["555f9fcfd7777119003acff8","555fa01d336c041700a9b832","5581f2958625220d00429ee1"],"title":"GCM","slug":"gcm","order":5,"from_sync":false,"reference":false,"_id":"555f9e9ed7777119003acfee","version":"555f9bf814d68e0d0096658a","project":"555f9bf814d68e0d00966587","__v":3,"createdAt":"2015-05-22T21:24:46.312Z"},"createdAt":"2015-06-17T22:20:05.842Z","parentDoc":null,"version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["555f9bf814d68e0d0096658b","555f9e9ed7777119003acfee","555fa040d7777119003acffd","555fa344d7777119003ad00b","555fa3e6d7777119003ad00f","555fb694336c041700a9b86e","555fb779336c041700a9b86f","555fb86bd7777119003ad039","555fbf1a336c041700a9b87f"],"_id":"555f9bf814d68e0d0096658a","project":"555f9bf814d68e0d00966587","releaseDate":"2015-05-22T21:13:28.470Z","__v":9,"createdAt":"2015-05-22T21:13:28.470Z"},"__v":0,"githubsync":"","project":"555f9bf814d68e0d00966587","user":"555f9a010758330d000d531a"}

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]