如何向特定的 Android 用户组发送 Firebase 推送通知

How to send firebase push notification to specific group of user for android(如何向特定的 Android 用户组发送 Firebase 推送通知)
本文介绍了如何向特定的 Android 用户组发送 Firebase 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Firebase 创建了推送通知服务,我可以向具有 FCM id 的所有或单个用户发送通知,但我不知道如何发送给特定用户.

I Have created push notification service using Firebase and I can send notification to either all or single user having FCM id, but I have no idea how to send to specific user.

服务器面板也不是为处理推送通知而创建的,如果有任何建议会有所帮助.

Also server panel is not created for handling push notification handling If any suggestion for that is there will help more.

推荐答案

Firebase 云消息传递 (FCM) 主题消息传递允许您向已选择加入特定主题的多个设备发送消息.基于发布/订阅模型,主题消息支持每个应用程序的无限订阅,即您的组附加到特定主题,如新闻组、体育组等.

Firebase Cloud Messaging (FCM) topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions for each app i.e your group is attached to specific topic like news group,sports group etc.

FirebaseMessaging.getInstance().subscribeToTopic("news");

取消订阅unsubscribeFromTopic("news")

从服务器端,您需要设置特定主题,即一组用户,如下所示:

From Server side you need to set up for specif topic i.e a group of user like this:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{
  "to": "/topics/news",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}

"/topics/news" 这将向订阅新闻主题的人群发送通知

"/topics/news" This will send notification to group of people who have subsribe the news topic

这篇关于如何向特定的 Android 用户组发送 Firebase 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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)