【问题标题】:Notification alert is shown only for the first message通知警报仅针对第一条消息显示
【发布时间】:2013-09-19 00:26:45
【问题描述】:

我有以下显示通知的方法:

private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                _context.getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.menu_cartable,
                "you have a new message",
                System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.sound = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        Intent notificationIntent = new Intent(_context, ActCartable.class);
        PendingIntent intent = PendingIntent.getActivity(_context, 0,
                    notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        notification.setLatestEventInfo(_context,
                "you have a new message",
                msg,
                intent);

        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }

在 Android 4.2 中,当第一次收到消息时(通知栏被清除),通知栏中会显示一个大图标(tickerText),几秒钟后它会被隐藏并通知转到通知栏。如果我没有打开该通知(通知栏未清除)并收到第二条消息,则不会再次显示 大图标,但设备会正确发出声音并更新新消息的内容如果用户打开通知栏,则在通知栏中成功。

您应该知道 大图标 在 android 3.x 中一直显示。

如何在 android 4.x 中每次收到新消息且通知栏未清除时显示该大图标?

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    例如,您可以取消旧通知并显示具有另一个 ID 的新通知。它看起来像这样:

    mNotificationManager.cancel(notificationId);
    mNotificationManager.notify(notificationId++, notification);
    

    @breceivemail 更新:

    如果您将++ 放在notificationId 之前,它可以正常工作,如下所示:

     mNotificationManager.cancel(notificationId);
     mNotificationManager.notify(++notificationId, notification);
    

    谢谢,

    【讨论】:

    • 是的,你是对的,当我测试它时,我在取消中增加了 notificationId。
    猜你喜欢
    • 2012-06-04
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    相关资源
    最近更新 更多