9

Notifyいくつかの基準に基づいてユーザーにしようとしています。Multiple Notificationsに表示されてStatus BarGroup the notification in single notificationますが、ユーザーが をクリックするとStatus Bar、そのグループのすべての通知を取得したいと考えています。それは可能ですか?PendingIntentsまたは、それらの通知を維持する必要がありますか? どんな助けでも大歓迎です。たとえば、2 人の友人の誕生日が同じ日に来る場合、2 つの通知を表示する必要があります。これらの通知を結合したい。つまり、ステータス バーの 2 つの通知の代わりに 1 つが必要です。ユーザーがクリックすると、2 つの通知に関する情報が必要です。出来ますか?

通知を表示するには、以下のコードを参照してください。

public void displayNotification(BirthdayDetail detail)
    {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentTitle(detail.getContactName());
        builder.setContentText(detail.getContactBirthDate());

        Intent resultIntent =  new Intent(this.context, NotificationView.class);
        resultIntent.putExtra("name", detail.getContactName());
        resultIntent.putExtra("birthdate", detail.getContactBDate());
        resultIntent.putExtra("picture_path", detail.getPicturePath());
        resultIntent.putExtra("isContact", detail.isFromContact());
        resultIntent.putExtra("notificationId", notificationId);

        if(detail.isFromContact())
        {
            resultIntent.putExtra("phone_number", detail.getPhoneNumber());
        }

        PendingIntent resultPendingIntent = PendingIntent.getActivity(this.context, requestCode++,
                resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);

        notificationManager 
                    = (NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, builder.build());
        notificationId++;
    }
4

1 に答える 1

7

同じ種類のイベントに対して複数回通知を発行する必要がある場合は、まったく新しい通知を作成することは避けてください。代わりに、値の一部を変更するか値を追加するか、またはその両方を行って、以前の通知を更新することを検討する必要があります。

次のようなものを使用できます。

mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
int notifyID = 1;
mNotifyBuilder = new NotificationCompat.Builder(this)
    .setContentTitle("New Message")
    .setContentText("You've received new messages.")
    .setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
// Start of a loop that processes data and then notifies the user
...
    mNotifyBuilder.setContentText(currentText)
        .setNumber(++numMessages);
    // Because the ID remains unchanged, the existing notification is
    // updated.
    mNotificationManager.notify(
            notifyID,
            mNotifyBuilder.build());

ソース: http://developer.android.com/training/notify-user/managing.html

于 2014-05-30T07:12:50.383 に答える