2017-05-26 122 views
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控制檯中定義了主題「照片」。什麼可能是這個問題,除了一切工作到今天爲止?真的很奇怪我。

回答

0

也許您擁有多個部署環境集,並且您在Play商店中啓動應用程序時已更改爲生產,並且在Firebase中只添加了開發中的數據。這對我來說是一個問題,我只在開發中設置數據,當我向客戶端發佈一個版本時,該應用程序沒有任何數據(分段爲空)。