SHARE
TWEET

Untitled

a guest Mar 20th, 2017 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top