The application is in PhoneGap. I am using push notification feature with https://github.com/marknutter/GCM-Cordova
I implemented the whole feature and it worked fine until yesterday. When I checked the app last day, push notification is not working when the app is not running. All notifications are receiving on my device, clicking on the message opens the app.
But the controls are not receiving at the javascript portion where message notification handles.
Code from file GCMIntentService.java:
JSONObject json;
json = new JSONObject().put("event", "message");
json.put("message", extras.getString("message"));
json.put("link", extras.getString("link"));
Log.v(ME + ":onMessage ", json.toString());
GCMPlugin.sendJavascript( json );
// Send the MESSAGE to the Javascript application
This code will work when the message received. But at that time, App is not running.
When I click on the notification message, the app opens as usual, not registering the message event; thereby not getting the control in JavaScript to handle push notification.
Code for CORDOVA_GCM_script.js is available at:
https://github.com/marknutter/GCM-Cordova/blob/master/assets/www/CORDOVA_GCM_script.js
Note: It works fine when the app is running.
EDIT: The notification runs sometimes. JavaScript is getting message event randomly.
EDIT 2:
I definitely know the problem.
From the java file, it triggers the javascript code when opening the app by clicking on the push notification message. But at that time, the WebView is not loaded, so not able to execute the script (which is an event trigger). Is this is the condition, everyone using the plugin will experience the same. Is there any workaround or any fix for it?
Am I doing anything wrong?
Using GCM-Cordova plugin will not handle the notification correctly if the application is not running. It is because the WebView was not loaded at the time when the plugin initiate the javascript.
Solution:
Finally able to solve this issue with the help of two plugins - GCM-Cordova and custom plugin.
IvenMS - I too am having the same problem so you are not the only one. If I understand praneetloke correctly, the Push Notifications will not work with PhoneGap apps which are not currently running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With