Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
- @Override
- public void onTokenRefresh() {
- String refreshedToken = FirebaseInstanceId.getInstance().getToken();
- // Check if the user is logged in. If so,
- // send the Firebase token to the server.
- if (PreferenceUtils.isLoggedIn(this)) {
- ApiInterface apiService = ApiClient.createService(ApiInterface.class, PreferenceUtils.getAuthToken(context));
- Call<BasicResponse> call = apiService.sendDeviceToken(token);
- call.enqueue(new Callback<BasicResponse>() {
- @Override
- public void onResponse(Call<BasicResponse> call, Response<BasicResponse> response) {
- if (!response.isSuccessful()) {
- // WHAT SHOULD I DO IF THE TOKEN FAILS TO GET SENT TO THE SERVER?
- }
- }
- @Override
- public void onFailure(Call<BasicResponse> call, Throwable t) {
- //
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement