{"action":"created","issue":{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/1214","repository_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push","labels_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/1214/labels{/name}","comments_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/1214/comments","events_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/1214/events","html_url":"https://github.com/phonegap/phonegap-plugin-push/issues/1214","id":176446884,"number":1214,"title":"Messages sometimes not getting overridden correctly","user":{"login":"MBuchalik","id":8061217,"avatar_url":"https://avatars.githubusercontent.com/u/8061217?v=3","gravatar_id":"","url":"https://api.github.com/users/MBuchalik","html_url":"https://github.com/MBuchalik","followers_url":"https://api.github.com/users/MBuchalik/followers","following_url":"https://api.github.com/users/MBuchalik/following{/other_user}","gists_url":"https://api.github.com/users/MBuchalik/gists{/gist_id}","starred_url":"https://api.github.com/users/MBuchalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MBuchalik/subscriptions","organizations_url":"https://api.github.com/users/MBuchalik/orgs","repos_url":"https://api.github.com/users/MBuchalik/repos","events_url":"https://api.github.com/users/MBuchalik/events{/privacy}","received_events_url":"https://api.github.com/users/MBuchalik/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/labels/android","name":"android","color":"BFD4F2"},{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/labels/docs","name":"docs","color":"FEF2C0"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-12T18:21:31Z","updated_at":"2016-09-14T09:04:20Z","closed_at":"2016-09-14T09:04:20Z","body":"I am sending two messages using GCM to my Android phone.\r\n\r\n### Expected Behaviour\r\nThe second notification overrides the first one.\r\n\r\n### Actual Behaviour\r\nThis seems to happen only after restarting the device: Sometimes, the second message is shown. Sometimes, the first one is shown. And sometimes, the \"wrong\" badge number is shown (so if message 1 is shown, it still shows the badge number of the second notification and vice versa).\r\n\r\n### Reproduce Scenario (including but not limited to)\r\n\r\n#### Steps to Reproduce \r\nRestart the device. While it is loading, send yourself two messages. I have created a small php script that allows me to test it easier - you can find it below.\r\n\r\nIt is a bit unfortunate: I cannot find out when this happens. As stated above - this seems to happen \"randomly\". But I have only managed to reproduce this after the device was restarted. It seems like most of the times the message gets overridden correctly - but in approximately 1 out of 3 messages, the wrong one is shown.\r\nWhat I do all the time: airplane mode is turned on and wifi is turned off. Then I restart the device, turn off airplane mode to enter my PIN, turn it back on and then I turn on wifi.\r\n\r\nThe last time I managed to get this behavior, I did the following:\r\nSend myself a test message, click on it so that the app opens. Then, close the app and turn off wifi. Restart the device and call the php script below two times with a delay of maybe 4 seconds - one time with the count set to 1 and the other time with the count set to 2. When the device is turned back on, turn off airplane mode, enter PIN code, turn it back on, turn on wifi and wait. I can see that the two messages arrive: There is a short animation in the status bar showing me the title of the two messages. At first, the message \"This is message 2\" appears and is replaced by \"This is message 1\". The badge, however, is 2. So, in the end, I see \"This is message 1\" and the badge \"2\" on my application's icon.\r\n\r\nHave you experienced something similar? I am not a developer for native Android code but this looks a bit like a race condition to me. Is there anything I can to to prevent it (or to assist you with finding the reason for this behavior)?\r\n\r\n#### Platform and Version (eg. Android 5.0 or iOS 9.2.1)\r\nAndroid 5.0.2\r\n\r\n#### (Android) What device vendor (e.g. Samsung, HTC, Sony...)\r\nSamsung (Galaxy Alpha)\r\n\r\n#### Cordova CLI version and cordova platform version\r\n\r\nPGB with cli-6.3.0\r\n\r\n#### Plugin version\r\n\r\n1.8.1 (from NPM)\r\n\r\n#### Sample Push Data Payload\r\nSee below\r\n\r\n#### Sample Code that illustrates the problem\r\nThe script I used to test it:\r\n``` php\r\ndefine( 'API_ACCESS_KEY', 'My gcm access key' );\r\n\r\n\r\n$registrationIds = array(\"my registration ID\" );\r\n\r\n$count = 0;\r\nif(isset($_REQUEST['badge']))\r\n\t$count = $_REQUEST['badge'];\r\n$msg = array\r\n(\r\n    'message'       => $count .' unread messages',\r\n    'badge' => $count,\r\n    'title'         => 'This is message ' . $count,\r\n    'vibrate'   => 1,\r\n    'sound'     => 1,\r\n    'ledColor' => array(0, 255, 255, 255)\r\n);\r\n\r\n$fields = array\r\n(\r\n    'dry_run' => false,\r\n    'registration_ids'  => $registrationIds,\r\n    'data'              => $msg\r\n);\r\n\r\n$headers = array\r\n(\r\n    'Authorization: key=' . API_ACCESS_KEY,\r\n    'Content-Type: application/json'\r\n);\r\n\r\n$ch = curl_init();\r\ncurl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );\r\ncurl_setopt( $ch,CURLOPT_POST, true );\r\ncurl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );\r\ncurl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );\r\ncurl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );\r\ncurl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );\r\n$result = curl_exec($ch);\r\ncurl_close($ch);\r\nprint_r($result);\r\n```\r\nThe response from GCM shows no errors. But this can't be the problem anyways since both messages arrive on the device for sure - the badge number wouldn't be 2 and the message \"This is message 1\" if one of the messages didn't arrive on the device."},"comment":{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/comments/246950782","html_url":"https://github.com/phonegap/phonegap-plugin-push/issues/1214#issuecomment-246950782","issue_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/1214","id":246950782,"user":{"login":"MBuchalik","id":8061217,"avatar_url":"https://avatars.githubusercontent.com/u/8061217?v=3","gravatar_id":"","url":"https://api.github.com/users/MBuchalik","html_url":"https://github.com/MBuchalik","followers_url":"https://api.github.com/users/MBuchalik/followers","following_url":"https://api.github.com/users/MBuchalik/following{/other_user}","gists_url":"https://api.github.com/users/MBuchalik/gists{/gist_id}","starred_url":"https://api.github.com/users/MBuchalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MBuchalik/subscriptions","organizations_url":"https://api.github.com/users/MBuchalik/orgs","repos_url":"https://api.github.com/users/MBuchalik/repos","events_url":"https://api.github.com/users/MBuchalik/events{/privacy}","received_events_url":"https://api.github.com/users/MBuchalik/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T09:04:20Z","updated_at":"2016-09-14T09:04:20Z","body":"@macdonst Thank you! I think that did the trick :+1: \r\nI have tried it a couple of times now and the correct message seems to be shown every time :smiley:"}}
{"actor":{"display_login":"MBuchalik"}}