【问题标题】:Behaviour of grouped notification on Android 7Android 7 上分组通知的行为
【发布时间】:2017-12-11 23:01:42
【问题描述】:

我创建了几个这样的通知:

public class NotificationCreator {
    Context context;
    int c = 0;

    public NotificationCreator(final Context context) {
        this.context = context;
    }

    void create() {

        String text = "" + c  + " " + new Date().toGMTString();

        // Intent
        Intent intent = new Intent(context, SecondActivity.class);
        intent.putExtra(SecondActivity.KEY, text);
        Intent[] intents = new Intent[1];
        intents[0] = intent;
        PendingIntent pendingIntent = PendingIntent.getActivities(
                context,
                c,
                intents,
                PendingIntent.FLAG_CANCEL_CURRENT);

        // Build notification
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.notification);
        builder.setContentTitle("Test");
        builder.setContentText(text);
//        builder.setGroup("");
        builder.setContentIntent(pendingIntent);
        Notification notification = builder.build();

        // Send notification
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(NOTIFICATION_SERVICE);

        notificationManager.notify(c, notification);

        c++;
    }
}

Android 7 上的结果是:

系统已将所有通知分组。

当我在构建器上明确设置时:

 builder.setGroup("myGroup");

结果是:

通知分组,而是单独显示,尽管都具有相同的组键。

  1. 这是预期的行为吗?

  2. 在第一种情况(分组)中,我能否确定当用户单击分组通知时会发生什么?个人意图似乎被忽略了,只是打开了应用程序。

【问题讨论】:

  • 添加组时是否尝试将setGroupSummary(true) 添加到构建器?喜欢这里stackoverflow.com/a/41114135/2910520。顺便说一句,这是正确的行为,不是来自同一个应用程序堆栈的分组通知,而分组的通知可以扩展或缩小,here 你可以找到一个 GIF
  • 我也有同样的问题。
  • 同样的问题,也尝试 setGroupSummary(true) 为每个通知,仍然相同的结果。

标签: android android-notifications android-7.0-nougat


【解决方案1】:

遇到了同样的问题,并通过使用“摘要通知”解决了这个问题。基本上,您使用所需的组创建一个常规通知,并使用同一组和setGroupSummary(true) 创建“摘要通知”。

更多https://blog.stylingandroid.com/nougat-bundled-notifications/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多