我使用fcm有问题。
我想在特定的时间发送一条消息,所以我设置了 setEventTimeInMillis(AndroidNotification.Builder)
在firebase admin sdk中,但fcm会立即发送消息,而不是在设置的时间发送消息。
时间格式不对吗?
我的代码如下:
public void sendMessage(String token) throws Exception {
String response = FirebaseMessaging.getInstance().send(androidMessage(token, UtcToMillis(null)));
log.info("Fcm Response : {}", response);
}
public Message androidMessage(String token, long time) throws Exception{
Message message = Message.builder()
.setNotification(Notification.builder()
.setTitle("FCM Test Message")
.setBody("Hi, This is FCM test Message")
.build())
.setAndroidConfig(AndroidConfig.builder()
.setNotification(AndroidNotification.builder()
.setEventTimeInMillis(time)
.setLocalOnly(true)
.setPriority(AndroidNotification.Priority.HIGH)
.setTitle("AndroidNotification test title")
.setBody("AndroidNotification test body")
.build())
.build())
.setToken(token)
.build();
return message;
}
public Long UtcToMillis(String time) throws Exception{
String utcTimeString = "2020-11-23T07:58:54.420000000Z";
long milliseconds = LocalDateTime.parse(utcTimeString, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS000000'Z'"))
.atOffset(ZoneOffset.UTC)
.toInstant()
.toEpochMilli();
return milliseconds;
}
暂无答案!
目前还没有任何答案,快来回答吧!