set FCM high-priority when using firebase-admin

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-19 06:19:29

问题


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);

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"?


回答1:


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.

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



来源:https://stackoverflow.com/questions/49601822/set-fcm-high-priority-when-using-firebase-admin

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