How to send FCM notification to a topic group from app using android studio [duplicate]

こ雲淡風輕ζ 提交于 2020-07-31 04:54:29

问题


I am trying to make push notifications using FCM in which any user subscribed to the topic "Alerts" can send a notification to others. I can recieve notifications sent using the FCM testing system. But when I was reffering to the documentation for sending push notifications, it gave me this code

String topic = "highScores";

// See documentation on defining a message payload.
Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setTopic(topic)
    .build();

// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

I had 2 problems in this First, the class named message does not exist. After much research, I found out the message class was deprecated and RemoteMessage had to be used but the RemoteMessage documentation had no proper instructions on how to do this.I need help in that
Second, a very small problem but does the topic name have to be the channel name or the topic to which everyone is subscribed to? Even sending the message to a list of tokens will be perfect

来源:https://stackoverflow.com/questions/62718798/how-to-send-fcm-notification-to-a-topic-group-from-app-using-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!