像whatsapp这样的组fcm通知,但允许多个组通知

Group fcm notifications like whatsapp but allowing multiple group notifications(像whatsapp这样的组fcm通知,但允许多个组通知)
本文介绍了像whatsapp这样的组fcm通知,但允许多个组通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否完全可能,但我会说明我的要求.如果可能的话,请帮我弄清楚该怎么做.

I am not sure whether this is entirely possible but I'll state my requirement. If it is possible then kindly help me figure out how to do it.

假设我有一个画廊类型的 Android 应用程序.当用户喜欢或评论图库中的照片时,我们会使用下面给出的代码触发 fcm 通知

Let's say I have a gallery kind of an android app. When the user likes or comments on a photo in the gallery, We'd trigger an fcm notification using the code given below

    value++;
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification)
            .setLargeIcon(rawBitmap)
            .setContentTitle("MyApp")
            .setContentText(ContentText)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(ContentText))
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(value, notificationBuilder.build());

通过添加 InboxStyle,我们可以将通知分组为一个并增加计数.(例如,您有 5 个通知)

By adding InboxStyle we can group notifcations into a single one and just increase the count.(For e.g. You have 5 notifications)

      NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();
            // Sets a title for the Inbox in expanded layout
            inboxStyle.setBigContentTitle("Title - Notification");
            inboxStyle.setSummaryText("You have "+value+" Notifications.");
            notificationBuilder.setStyle(inboxStyle);

但我的要求就像为单独的照片单独分组.如果用户留下 2 条评论,每条评论 3 张照片.我需要列出三组通知.更像是您对这张照片有 2 条评论,对这张照片有 2 条评论,以此类推.

But my requirement is like separate grouping for separate photos. If the user leaves 2 comments each for 3 photos. I need three groups of notifications to be listed. More like you have 2 comments on this photo,2 on this and so on.

如果有帮助,我会收到照片的唯一 ID.

I'll be receiving unique ids for the photos,if that helps.

How long will the id be retained?

假设用户对 id 为 001 的照片发表了 2 条评论,而合作伙伴作为一个群组收到通知.

Let's assume the user drops 2 comments on photo with id 001 and the partner receives the notification as a group .

What happens when the user drops another 2 comments on photo with id 002?
Will there be 2 groups?

因为一组 id 为 001 的通知保持不变.

Because a group of notification with id 001 remains untouched.

推荐答案

我会使用 TAG 参数.对于每组消息,您应该使用不同的 TAG.

I would use the TAG parameter. For each group of messages you should use a different TAG.

例如:

消息 1)

{
    "notification": {
        "title": "PhotoApp: photo 123",
        "body": "You have 1 notification",
        "click_action" : "OPEN_MAINACTIVITY",
        "icon": "ic_launcher",
        "color": "#ffffff"
        "tag": "photo123"
    },
    "registration_ids":[
        "--your_id--"
    ]
}

消息 2)

{
    "notification": {
        "title": "PhotoApp: photo ABC",
        "body": "You have 1 notification",
        "click_action" : "OPEN_MAINACTIVITY",
        "icon": "ic_launcher",
        "color": "#ffffff"
        "tag": "photoABC"
    },
    "registration_ids":[
        "--your_id--"
    ]
}

消息 3)

{
    "notification": {
        "title": "PhotoApp: photo 123",
        "body": "You have 2 notifications",
        "click_action" : "OPEN_MAINACTIVITY",
        "icon": "ic_launcher",
        "color": "#ffffff"
        "tag": "photo123"
    },
    "registration_ids":[
        "--your_id--"
    ]
}

这将仅显示 2 个通知警报.一个用于 Photo123,显示有 2 个通知(最后一条消息),另一个用于 PhotoABC,显示只有 1 个通知.

This will show only 2 notification alerts. One for Photo123, showing there are 2 notifications (last message), and the other for PhotoABC, showing there is just 1 notification.

这里最重要的是TAG参数.它会根据需要对通知进行分组,

The most important thing here is the TAG parameter. It will group notifications as you need,

希望我明确表示对您有所帮助.

Hope I made myself clear at it helps you out.

一些有用的链接:

FCM 文档

类似的问题

这篇关于像whatsapp这样的组fcm通知,但允许多个组通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)