堆栈通知在一起

时间:2016-10-24 02:44:30

标签: android android-notifications

我正在尝试堆叠通知,但我收到的是单独的通知。 这是代码:

final static String GROUP_KEY_SIGNALS = "group_key_signals";
private static int id = 0;    

public void onMessageReceived(RemoteMessage remoteMessage) {
    showNotification(remoteMessage.getData().get("message"));
}

private void showNotification(String message) {

    Intent i = new Intent(this,MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, id, i, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("Test")
            .setContentText(message + " id=" + id)
            .setStyle(new NotificationCompat.InboxStyle()
                    .addLine(message)
                    .setSummaryText("Click for more details"))
            .setGroup(GROUP_KEY_SIGNALS)
            .setColor(Color.BLACK)
            .setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(id++, builder.build());
}

我正在递增ID,但我仍将组设置为GROUP_KEY_SIGNALS。 不确定我做错了什么

0 个答案:

没有答案