I work with Notification GCM in cordova android apps. when the application is running in background and a notification came it is displayed in the status bar of the device. when more than two notifications are displayed in this status bar, I tap on first notification (displayed in the status bar), the application opens and it displays the notification message, when I tap on the second notification all of the remaining notifications(in the status bar) vanish. In this fonction, when I tap on the notification, the part (! e.foreground) runs.

function onNotificationGCM(e) {

  switch( e.event )
   {
    case 'message':


        if (e.foreground)
        {   
            // playAudio('http://oringz.com/oringz-uploads/sounds-1068-the-calling.mp3');
            navigator.notification.beep(1);
            msgNotification(e.payload.message);
            $("#toastContainer").dxToast('instance').show();
            var notif={message:e.payload.message};
            popovernotifListe.push(notif);
            nbrnotif(nbrnotif()+1);

        }
        else if (!e.foreground)
        {

             if (e.coldstart) {
                    console.log("App was not running and user clicked on notification");
            } else {
                console.log("App was running and user clicked on notification");
            }
            msgNotification(e.payload.message);
            $("#toastContainer").dxToast('instance').show();
            nbrnotif(nbrnotif()+1);
            var notif={message:e.payload.message};
            popovernotifListe.push(notif);

        }
        break;

        case 'error':
          console.log('GCM error = '+e.msg);
        break;

        default:
          console.log('An unknown GCM event has occurred');
        break;
}

}

1

There are 1 answers

0
Ajoy On

If the notification ID is not sent from your server, each notification is created with an ID 0.

To fix this problem, you will have to set the notification ID for each notification you create. You can set the notification ID by sending a parameter notID from the server, with each notification, which will be used to create a notification.