I have seen multiple similar items but no one was in the same context (with angular, not using ionic). I am using cordova 5.0.0 (cordova --version in cmd shows 5.0.0, in the device plugin module I see 3.6.4)
I have an angular based application that runs inside a Cordova application. I am trying to add push notification using the PushPlugin.
I am able (inside the main module) to call the register
method of the push plugin and in Android (currently only device I test on) the "success" handler is called. The ecb though is never called regardless of where I put the callback function.
In my app.js:
angular.module('myApp', [...]).config().run(['$rootScope',...,
function($rootScope,...) {
// etc etc...
document.addEventListener("deviceready", function(){
var pushNotification = window.plugins.pushNotification;
pushnotification.register(
successHandler,
errorHandler,
{
"senderID":"<sender_id>",
"ecb":"window.onNotification"
});
});
// this is invoked
function successHandler (result) {
alert('result = ' + result);
};
function errorHandler (error) {
alert('error = ' + error);
};
// option 1:
function onNotification(e) {...};
// option 2:
var onNotification = function(e) {...};
// option 3
// (tried below and above the call to register
// though I believe it doesn't matter):
window.onNotification = function(e) {...};
}]);
// option 4:
var onNotification = function(e) {...};
So far, none of them work. I assume that I am doing something wrong with the scope but I am not sure what.
Is it something with the scope? Could it be something else? What? How to diagnose?
EDIT: I checked the logcat and some thing does not make sense:
I/chromium ( 3981): [INFO:CONSOLE(217)] "registering with GCM", source: file:///android_asset/www/js/app.js (217)
V/PushPlugin ( 3981): execute: action=register
V/PushPlugin ( 3981): execute: data=[{"senderID":"SENDER_ID","ecb":"window.onNotification"}]
V/PushPlugin ( 3981): execute: jo={"senderID":"SENDER_ID","ecb":"window.onNotification"}
V/PushPlugin ( 3981): execute: ECB=window.onNotification senderID=SENDER_ID
D/GCMRegistrar ( 3981): resetting backoff for com.my.app
V/GCMRegistrar ( 3981): Registering app com.my.app of senders SENDER_ID
W/ActivityManager( 1254): Unable to start service Intent {act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } U=0: not found
The plugin version I see (cordova plugin list) is 2.4.0. How come the intent is c2dm? Shouldn't it use the newer GCM?