【发布时间】:2014-09-05 14:07:01
【问题描述】:
Android 应用程序的 com 推送通知,一切运行良好,但假设我每天发送 5 个推送通知,我不希望用户在他的手机上一次看到 5 个通知图标。最好他只看到一个。他们删除旧通知并只显示最新通知的任何方式也是如此。
【问题讨论】:
标签: android push-notification parse-platform google-cloud-messaging
Android 应用程序的 com 推送通知,一切运行良好,但假设我每天发送 5 个推送通知,我不希望用户在他的手机上一次看到 5 个通知图标。最好他只看到一个。他们删除旧通知并只显示最新通知的任何方式也是如此。
【问题讨论】:
标签: android push-notification parse-platform google-cloud-messaging
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
显示通知的方法有一个表示通知标识符的 int 参数。如果您使用常量标识符,则每个新通知都会替换之前的通知。
【讨论】:
您必须将通知 ID 设置为相同的值。因此,它们会在每个到达时被替换。
【讨论】:
int notificationId = 1 ;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.gcm_logo);
builder.setContentTitle("Test Title");
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, builder.build());
因此您可以为不同类型的通知维护通知 ID。如果您为每个通知保留相同的通知 ID,那么它将在相同的 .
如果您在待定意图中有任何附加内容,并且您想用最新的内容更新这些附加内容,则使用以下命令生成待处理意图:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), PendingIntent.FLAG_ONE_SHOT);
【讨论】: