分组Android通知

时间:2016-06-18 09:32:31

标签: android push-notification notifications android-notifications

以下代码在创建通知及其语音和操作方面与我合作正常。

但看起来.setGroup(GROUP_KEY_Fonix)无效,因为通知没有组合在一起,我在这里遗漏了什么!

public int notificationID = 0;
final static String GROUP_KEY_Fonix = "fonix_notification";

private void Notify(String notificationTitle, String notificationMessage){
    notificationID++;

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

// intent triggered, you can add other intent for other actions
    Intent intent = new Intent(MainActivity.this, NotificationView.class);
    PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

// Build the notification, setting the group appropriately
    Notification notif = new NotificationCompat.Builder(this)
            .setGroup(GROUP_KEY_Fonix)
            .setContentTitle("New note: " + notificationTitle)
            .setContentText(notificationMessage)
            .setSmallIcon(R.drawable.ic_stat_new_message)
            .setContentIntent(pIntent)
            .setSound(soundUri)
            .addAction(R.drawable.ic_stat_new_message, "View", pIntent)
            .addAction(0, "Remind", pIntent)
            .build();

// Issue the notification
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    // hide the notification after its selected
    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(notificationID, notif);
}

1 个答案:

答案 0 :(得分:1)

此外,您应该创建组摘要通知。为此,只需使用此代码:

Notification notificationSummary = new NotificationCompat.Builder(this)
        //Set content
        .setGroup(GROUP_KEY_Fonix)
        .setGroupSummary(true)
        .build();

notificationManager.notify(notificationSummaryId, notificationSummary);

了解详情here