使用firebase推送通知

问题描述 投票:0回答:2

我有一个项目,我正在使用firebase我想在按下它时自动向所有用户发送通知时按下按钮。我找不到这样的东西。我希望任何代码都能做到这一点。

请救救我的生活。

android firebase push-notification onclick firebase-cloud-messaging
2个回答
0
投票

看起来您需要为每个客户订阅相同的主题,然后发送推送到所述主题。

https://firebase.google.com/docs/cloud-messaging/android/send-multiple?authuser=0


0
投票

首先,您需要从firebase获取所有寄存器设备令牌。

然后你需要创建JSON对象:

 JSONObject json = new JSONObject();
 json.put("to",/* device tooken*/);
 json.put("use to","/topics/all");
 json.put("notification",/* notifications Messgae */);

之后,您需要在下面给定的URL上点击API调用。您可以使用排球,翻新或其他您感觉舒适的东西

https://fcm.googleapis.com/fcm/send

但是您需要使用API​​调用添加标头,这是强制性的:

“授权”,/ SERVER_KEY / “内容类型”,“应用/ JSON”;

有关更多说明,请查看here

它适合你。

© www.soinside.com 2019 - 2024. All rights reserved.