简体   繁体   English

多个通知在Android上不起作用

[英]Multiple notifications not working on Android

Whenever I receive a push notification on Android it replaces any existing notification in the drawer. 每当我在Android上收到推送通知时,它都会替换抽屉中任何现有的通知。 any idea to fix that? 有什么办法解决吗?

Below is my code: 下面是我的代码:

NotificationManager notificationManager = (NotificationManager)
                                getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(DbInsertService.this, MessageActivity.class);
intent.putExtra("Service",serviceType);
PendingIntent pIntent = PendingIntent.getActivity(DbInsertService.this, (int) 
   System.currentTimeMillis(), intent,PendingIntent.FLAG_UPDATE_CURRENT);
 Notification n  = new Notification.Builder(DbInsertService.this)
                                .setContentTitle("Message from " +serviceType.getSer_name())
                                .setContentText(messageType.getHis_title())
                                .setSmallIcon(R.drawable.ic_email_variant_grey600_24dp)
                                .setContentIntent(pIntent)
                                .setAutoCancel(true).build();
                        notificationManager.notify(0, n);

thanks 谢谢

Set different Id for different notification. 为不同的通知设置不同的ID。

notificationManager.notify(0, n); // here set different Id. //在此设置不同的ID。

You're sending them all with the same id. 您要发送的所有ID都相同。 Send different ids and they won't overwrite. 发送不同的ID,它们不会被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM