小编Nik*_*ika的帖子

使用setGroup()工作的Kitkat(API 19)中的堆栈通知无法正常工作

我有一个问题,我无法找到答案.我已经尝试了AndroidDeveloper教程,我在这里搜索了stackoverflow和谷歌,但要么我的搜索技能很难或没有答案,我认为解决了我的问题.

我希望在有多个新消息时将消息通知堆叠到一个通知中.我可以为每条消息显示通知,但我无法进行堆栈/摘要通知.

我得到的最好的是:http://developer.android.com/images/android-5.0/notifications/Summarise_Dont.png

我想要的是:http://developer.android.com/images/android-5.0/notifications/Summarise_Do.png

我正在使用API​​ 19,它不必是后向兼容的.将我的代码写在AndroidStudio中并在Genymotion中进行测试.

我尝试使用NotificationCompatManager,结果是有多个通知: NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

我也尝试过使用NotificationManager相同的结果,即多个通知:

NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

我的通知如下:

Notification notification = new NotificationCompat.Builder(this) .setContentTitle( "New message from... ") .setContentText("Message:...") .setSmallIcon(R.drawable.icon) .setContentIntent(pIntent) .setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION)) .setGroup(mNoti) .setGroupSummary(true) .setAutoCancel(true) .build();

我点这样的通知:

notificationManager.notify(counter, notification);
Run Code Online (Sandbox Code Playgroud)

如果每个通知的计数器递增,则每个通知都有自己的ID.

我也试过这个表单来构建和激活通知,而不是succsess:

  NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("message from...")
                    .setContentText("message...")
                    .setContentIntent(pIntent)
                    .setAutoCancel(true)
                    .setGroup(mNoti)
                    .setGroupSummary(true)
                    .setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION));


    notificationManager.notify(counter, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)

setGroup显然对我有所帮助.我不明白为什么它不起作用或我应该如何使它工作.

我的小组看起来像这样:

final static String mNoti = "mNoti";
Run Code Online (Sandbox Code Playgroud)

唯一远远接近我想要的是对所有通知使用相同的ID,以便新通知覆盖旧通知,并在构建通知时使用setNumber(int).然而,这并没有真正给我我想要的结果,因为我认为我不能得到用户未处理的通知数量.或者我可以吗?

任何人都可以帮我达到我想要的目标吗?

notifications android android-4.4-kitkat

7
推荐指数
1
解决办法
6649
查看次数