2

I want to use inbox style notification, and once notification is still showing in notification status bar then it should append to the existing notification like gmail.

But I don't know how to detect that notification is showing in the status bar, Is there any way to get the notification id

Is ther any way to know that notification generated by my application is already displayed and just update it with +1 more(Inbox style)

What I thought :-

I thought I can store the notification id in shared prefrences and I will pass the pending intent which will start a intent service which will clear the notification is stored in shared prefrences and during notification posting I will check the notification id in prefrences If it is not cleared then I will update it

Does any one have any better idea ?

4

3 回答 3

1

我认为您应该在此链接上拥有所有内容:http: //developer.android.com/training/notify-user/managing.html

就像你说的,你需要知道通知 id 才能更新它。使用 Shared Preferences 是一种简单的方法,因为它只需几行代码即可完成所有操作,

你的想法很好,当用户点击通知时清除首选项文件。

于 2013-08-08T14:19:56.077 回答
1

不要将其保存在首选项中。只需使用一个常量值作为通知 ID。

static final int MY_NOTIFICATION_ID = 1;

由于每个应用程序的 ID 都是唯一的,因此您可以使用所需的编号。然后在通知 NotifiactionManager 时使用它。使用相同的代码更新您的通知。

NotificationManager.notify(MY_NOTIFICATION_ID , notification);
于 2013-10-30T15:27:12.247 回答
0

您可以使用静态变量来跟踪通知 ID 并附加通知,我的意思是堆叠通知,您也可以在静态变量中保留一个数字...

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(notificationTitle).setContentText(contentText);
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(notificationTitle + " Details");

            // Moves events into the big view
            for (int i = 0; i < extrasList.size(); i++) {
                inboxStyle.addLine(extrasList.get(i).getString(mString));
            }

            if (number >= 8) {
                inboxStyle.setSummaryText("+" + (number - 7) + " more reply(s)");
            } else {
                inboxStyle.setSummaryText(contentText);
            }
            mBuilder.setStyle(inboxStyle);
            mBuilder.setNumber(number);
            mBuilder.setContentIntent(contentIntent);
            mBuilder.setAutoCancel(true);
            mNotificationManager.notify(Integer.parseInt(type), mBuilder.build());
于 2014-02-10T11:37:56.070 回答