use of com.google.firebase.auth.GetTokenResult in project iosched by google.
the class RegistrationStatusService method getFirebaseToken.
/**
* Get Firebase token for current user
*/
private String getFirebaseToken() throws Exception {
FirebaseUser fbUser = mFirebaseAuth.getCurrentUser();
if (fbUser == null) {
throw new IOException("Firebase user not authenticated");
}
// Get Firebase token and wait for operation to complete
final CountDownLatch latch = new CountDownLatch(1);
Task<GetTokenResult> task = fbUser.getToken(false);
task.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
latch.countDown();
}
});
latch.await();
if (task.isSuccessful()) {
String fbToken = task.getResult().getToken();
if (fbToken == null) {
throw new IOException("Received null Firebase token");
}
return fbToken;
} else {
throw task.getException();
}
}
Aggregations