Search code examples
androidionic-frameworkcordova-plugin-fcm

FCM push notification is not working in android(Ionic project using cordova-plugin-fcm 2.1.1)


I am testing push notifications in an android project build using ionic 1. I have configured everything and getting the token from server for fcm.

in $ionicPlatform.ready of run() I have the following code.

if(window.FCMPlugin){
        FCMPlugin.onNotification(function(data){
            if (data.wasTapped) {
                $ionicPopup.alert({
                    title: data.title, 
                    template: '<p style="text-align:center">' + data.body + '</p>'
                });
            } else {
                //received foreground
                $ionicPopup.alert({
                    title: data.title,
                    template: '<p style="text-align:center">' + data.body + '</p>'
                });
            }
        });
        FCMPlugin.getToken(function(data){
            //$scope.token = data;
            console.log("token received");
        },
        function(err){
            $ionicPopup.alert({
                    title: "Error",
                    template: '<p style="text-align:center">Error in getting FCM Token</p>'
                });
        });
}

The problem is when I send fcm notification targeting a single device I am not getting the notification. But, the status of the notification in fcm console says it as a completed one. I am not getting any notification or call back after sending the notification. I have searched for solutions a long time online, couldn't find a solution. Any help is really welcome!


Solution

  • Solved! The test device's wifi connection proxy was causing the problem. When using personal wifi connection the device was able to receive notifications.