• 5
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Firebase/Android: Get current user email

I am trying to get the email address of the current user. I have the following code in my onCreate, but it isn't working:

FirebaseAuth.AuthStateListener authListener = new FirebaseAuth.AuthStateListener() {
    @Override
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
        FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
        if (firebaseUser != null) {
            userEmail = firebaseUser.getEmail();
        }
    }
};

Note that variable authListener at the top is "never used" according to my program. Not sure if this has anything to do with it. Does anyone know what could be wrong with the code I have above?

Update, got it working! The below code gets the current users email.

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user != null) {
                String userEmail = user.getEmail();
            } else {
                // No user is signed in
            }
  • 1
Reply Report