【发布时间】:2021-07-11 20:32:27
【问题描述】:
有一些用于计划任务的 Web 应用程序。如果添加了一项任务,通知将发送到应用程序,其中包含一些任务详细信息。 如果添加了第二个任务,则第一个通知将替换为第一个通知。 只显示一个通知,即第二个。
当应用在后台时,会显示 2 个通知。
但是一个应用程序在前台只显示一个通知。请帮帮我。
任何帮助将不胜感激。
这是我在应用处于前台时的通知代码。
if (!NotificationUtils.isAppIsInBackground(getApplicationContext())){
Intent intent = new Intent(Config.PUSH_NOTIFICATION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
intent.putExtra("Plan","fromFCM");
broadcastManager.sendBroadcast(intent);
Bitmap bitmapIcon = BitmapFactory.decodeResource(getResources(), R.drawable.notify_app_icon);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBulder = new NotificationCompat.Builder(this);
notificationBulder.setContentTitle(notificationData.getTitle());
notificationBulder.setContentText(notificationData.getTextMessage());
notificationBulder.setSmallIcon(R.drawable.notify_app_icon);
notificationBulder.setLargeIcon(bitmapIcon);
notificationBulder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationData.getTextMessage()));
notificationBulder.setAutoCancel(true);
//notificationBulder.setSmallIcon(R.mipmap.ic_launcher);
notificationBulder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(notificationData.getId(), notificationBulder.build());
/* Plan_Details plan_details = new Plan_Details();
plan_details.refreshPlan();*/
}
【问题讨论】:
-
试试onesignal push,它很容易定制,ho head ace
-
你能提供任何实现的链接吗@SamwinishereHere
-
转到 onesignal.com
-
你的 notificationData.getId() 总是唯一的吗?
标签: android firebase push-notification firebase-cloud-messaging