Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
  2. @Override
  3. public void onTokenRefresh() {
  4. String refreshedToken = FirebaseInstanceId.getInstance().getToken();
  5.  
  6. // Check if the user is logged in. If so,
  7. // send the Firebase token to the server.
  8. if (PreferenceUtils.isLoggedIn(this)) {
  9. ApiInterface apiService = ApiClient.createService(ApiInterface.class, PreferenceUtils.getAuthToken(context));
  10.  
  11. Call<BasicResponse> call = apiService.sendDeviceToken(token);
  12. call.enqueue(new Callback<BasicResponse>() {
  13. @Override
  14. public void onResponse(Call<BasicResponse> call, Response<BasicResponse> response) {
  15. if (!response.isSuccessful()) {
  16.  
  17. // WHAT SHOULD I DO IF THE TOKEN FAILS TO GET SENT TO THE SERVER?
  18.  
  19. }
  20. }
  21.  
  22. @Override
  23. public void onFailure(Call<BasicResponse> call, Throwable t) {
  24. //
  25. }
  26. });
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement