问题
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