我正在使用FCM向Android设备发送通知.当应用程序处于后台时,如果我发送10个通知,则设备将在通知栏上显示10个条目.
我希望FCM在通知栏上只输入一个条目,即较新的条目将覆盖旧条目.我在https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream上找不到设置密钥的密钥.
有办法吗,或者不可能?谢谢.
android android-notifications firebase firebase-cloud-messaging firebase-notifications
我尝试实现这样的组通知android group notification和ios group notification。但我做不到。我也试过这个flutter_local_notification插件。但这仅在应用程序打开时有效。不在前台(onResume)和后台工作。
void registerNotification() {
_fcm.configure(
onMessage: (Map<String, dynamic> message) {
return;
},
onResume: (Map<String, dynamic> message) {
return;
},
onLaunch: (Map<String, dynamic> message) {
return;
},
onBackgroundMessage: backgroundMessageHandler);
}
Run Code Online (Sandbox Code Playgroud)
有效载荷
const payload = {
notification: {
title: title,
body: message,
},
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
sound: "default"
},
android: {
priority: "high",
collapse_key: userName,//tried to add collapse_key for group notification
},
apns: {
headers: {
"apns-priority": "5",
},
},
token:token, …
Run Code Online (Sandbox Code Playgroud) 我Firebase Cloud Messaging
用来从我的服务器发送推送通知到我的Android应用程序.
当应用程序运行时,通知会堆叠,因为我将它们设置为我的组中的组FirebaseMessagingService
.这很好.
但是,当应用程序未运行时,通知不会堆叠,并且每个通知都会单独显示.这不好.
即使应用程序未运行,如何确保通知堆叠?
这是我的FirebaseMessagingService
样子:
public class MyFcmListenerService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notif_white)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.notif_white))
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText(notification.getBody())
.setAutoCancel(true)
.setPriority(2)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setGroup("1")
.setGroupSummary(true)
.setOnlyAlertOnce(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)