使用firebase-admin时设置FCM高优先级 [英] set FCM high-priority when using firebase-admin

查看:139
本文介绍了使用firebase-admin时设置FCM高优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,该代码使用firebase-admin通过Firebase云消息传递来发送消息

I have the following code which uses firebase-admin to send messages using Firebase cloud messaging

Message message = null;
message = Message.builder().putData("From", fromTel).putData("To", toTel).putData("Text", text)
            .setToken(registrationToken).build();

String response = null;
try {
    response = FirebaseMessaging.getInstance().sendAsync(message).get();
    responseEntity = new ResponseEntity<String>(HttpStatus.ACCEPTED);
} catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
}
System.out.println("Successfully sent message: " + response);

上面的代码工作正常.但是我需要发送高优先级"消息,以便设备在打ze模式下可以接收它们.

The above code works fine. But I need to send "high-priority" messages so that the device can receive them while in doze mode.

如何使消息成为高优先级"?

How can I make the messages "high-priority"?

推荐答案

要发送到Android设备,请在构建消息时设置其

For sending to Android devices, when building the message, set its AndroidConfig to a value that has Priority.HIGH:

AndroidConfig config = AndroidConfig.builder()
        .setPriority(AndroidConfig.Priority.HIGH).build();

Message message = null;
message = Message.builder()
        .putData("From", fromTel).putData("To", toTel).putData("Text", text)
        .setAndroidConfig(config) // <= ADDED
        .setToken(registrationToken).build();

有关其他详细信息,请参阅文档中的示例.

For additional details, see the example in the documentation.

当发送到Apple设备时,请使用setApnsConfig(),如

When sending to Apple devices, use setApnsConfig(), as explained in the documentation.

这篇关于使用firebase-admin时设置FCM高优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆