在android状态栏中出现多次推送通知时,第二个被触摸的人将消失 [英] Multiple push notification present in the status bar in android when the second is touched others vanish

查看:145
本文介绍了在android状态栏中出现多次推送通知时,第二个被触摸的人将消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cordova android应用程序中使用Notification GCM。
当应用程序在后台运行并且通知
时,它会显示在设备的状态栏中。
当这个状态栏显示两个以上的通知时,我点击第一条通知(显示在状态栏中),应用程序打开并显示通知消息,当我点击第二条通知时,所有剩余的通知(在状态栏中)消失。
在这个功能中,当我点击通知时,零件(!e.foreground)运行。

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;
}

}

}

推荐答案

如果通知ID不是从您的服务器发送的,则每个通知都使用ID 0 创建。

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

要解决这个问题,您必须设置通知ID 为您创建的每个通知。您可以通过从服务器发送参数 notID 来设置通知ID,每个通知将用于创建通知

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.

这篇关于在android状态栏中出现多次推送通知时,第二个被触摸的人将消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆