1
我在我的android应用程序和spring后端中使用了firebase通知。Firebase响应 - 空值响应
一切工作正常,但可能出现错误后,我释放我的Android版本谷歌Play商店进行测试。现在,我有这样的回应:
的通知发送,一切工作正常,但为什么我收到我的春天后端一个空值?
我的后端的Java Spring代码:
@RequestMapping(value = "/send", method = RequestMethod.GET,
produces = "application/json")
public ResponseEntity<String> send() {
JSONObject body = new JSONObject();
try {
body.put("to", "/topics/photos");
body.put("priority", "high");
JSONObject notification = new JSONObject();
notification.put("body", "body string here");
notification.put("title", "title string here");
JSONObject data = new JSONObject();
data.put("lat", "value1");
data.put("lng", "value2");
body.put("notification", notification);
body.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
HttpEntity<String> request = new HttpEntity<>(body.toString());
CompletableFuture<FirebaseResponse> pushNotification = androidPushNotificationsService.send(request);
CompletableFuture.allOf(pushNotification).join();
try {
FirebaseResponse firebaseResponse = pushNotification.get();
if (firebaseResponse.getSuccess() == 1) {
log.info("push notification sent ok!");
} else {
log.error("error sending push notifications: " + firebaseResponse.toString());
}
return new ResponseEntity<>(firebaseResponse.toString(), HttpStatus.OK);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return new ResponseEntity<>("the push notification cannot be send.", HttpStatus.BAD_REQUEST);
}
我得到空指针在这里,这是空的成功:
firebaseResponse.getSuccess()
的原因是什么?我在我的项目Firebase控制台中定义了主题“照片”。什么可能是这个问题,除了一切工作到今天为止?真的很奇怪我。