代码之家  ›  专栏  ›  技术社区  ›  Elnaz

多个通知在Android上不起作用

  •  0
  • Elnaz  · 技术社区  · 8 年前

    有没有办法解决这个问题?

    以下是我的代码:

    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);
    

    2 回复  |  直到 7 年前
        1
  •  1
  •   Drumil Jani    8 年前

    为不同的通知设置不同的Id。

    notificationManager.notify(0, n);

        2
  •  0
  •   Gabe Sechan    8 年前

    您使用相同的id发送它们。发送不同的id,它们将不会覆盖。