从服务器向安装了应用程序的用户段发送通知

San*_*idi 9 android firebase firebase-cloud-messaging

在Firebase控制台中,我看到了使用app"com.example"(其中com.example是应用名称)向User Segement发送通知的选项.

如图所示:

在此输入图像描述

但是如何使用FCM REST API从服务器端执行此操作:

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

AL.*_*AL. 5

遗憾的是,无法使用FCM REST API向用户段发送消息.

作为替代方案,您将必须使用其他方式向多个设备发送消息,例如仅使用registration_ids参数和主题消息(我认为最适合您的用例).

以下是如何使用PostmancURL发送此示例的示例.


小智 5

我找到了一个解决方案,您可以将您的应用订阅到特定主题,例如您的FirebaseInstanceIdService类中的应用包名称,这样您就可以发送数据按

 {
  "to" : "/topics/your_package_name",
  "data" : {
    "key1" : "value 1",
    "key2": "value 2",
   ...
  }
}
Run Code Online (Sandbox Code Playgroud)

这是在FirebaseInstanceIdService类中将您的应用订阅到主题的代码

     public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
    {
        private final String TAG="your_tag";
        @Override
        public void onTokenRefresh() {


        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        FirebaseMessaging.getInstance().subscribeToTopic("your_app_package_name");
        }
}
Run Code Online (Sandbox Code Playgroud)

它为我工作


Muh*_*ooq 0

您实际上需要向该主题发送消息..所有订阅该主题的成员都会收到您的消息..

只需查看链接..

https://developers.google.com/cloud-messaging/topic-messaging