Skip to content
Advertisement

Firebase Authentication: Update Email

I am using firebase to register my users, users can update their data but when updating the email they always send me the task unsuccessful response, and I verified that when updating the email it is well written. This is the code:

`private String vPassword, vEmail;
private Button btnValidate;
private EditText edContra, edEmail;
private TextView errorContra;
private ProgressDialog pDialog;
String sMail;

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_pop_reset_email);

    pDialog = new ProgressDialog (this);
    vPassword = getIntent (). getStringExtra ("password");
    vEmail = getIntent (). getStringExtra ("email");
    btnValidar = findViewById (R.id.btnValidar);
    edContra = findViewById (R.id.passwordValidate);
    edEmail = findViewById (R.id.correoValidar);
    errorContra = findViewById (R.id.errorContraValidar);

    DisplayMetrics measures = new DisplayMetrics ();
    getWindowManager (). getDefaultDisplay (). getMetrics (measures);

    int width = measurements.widthPixels;
    int high = measures.heightPixels;

    getWindow (). setLayout ((int) (width * 0.85), (int) (height * 0.5));

    btnValidar.setOnClickListener (new View.OnClickListener () {
        @Override
        public void onClick (View view) {
            String edPassword = edContra.getText (). ToString ();
            sMail = edEmail.getText (). toString ();
            if (edPassword.equals (vPassword)) {
                Verify ();
            } else {
                errorContra.setVisibility (View.VISIBLE);
            }
        }
    });
}

// CHECK EMAIL
private void Verify () {
    if (! sCorreo.isEmpty () && sCorreo.contains ("@") && sCorreo.contains (".")) {
        errorContra.setVisibility (View.INVISIBLE);
        pDialog.setMessage ("Updating ...");
        pDialog.setCanceledOnTouchOutside (false);
        pDialog.show ();
        UpdateMail ();
    } else {
        errorContra.setVisibility (View.VISIBLE);
        errorContra.setText ("* Type Valid Mail.");
    }
}

// UPDATE EMAIL
private void UpdateMail () {
    FirebaseUser user = FirebaseAuth.getInstance (). GetCurrentUser ();

    user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener <Void> () {
                @Override
                public void onComplete (@NonNull Task <Void> task) {
                    if (task.isSuccessful ()) {
                        Toast.makeText (PopResetEmail.this, "Mail Updated", Toast.LENGTH_SHORT) 
                        .show ();
                    } else {
                        Toast.makeText (PopResetEmail.this, "Email ERROR", Toast.LENGTH_SHORT) 
                        .show();                                          
                    }
                    pDialog.dismiss ();
                }
            });
}

// CLOSE ACTIVITY X
public void Close (View view) {
    finish ();
}`

Already verify that at the time of the mail update it is taken from the edit text and converted to a string.

When testing on my device when I press the button to update, this appears in the Logcast:

2020-08-02 08:43:40.045 7910-7910/com.example.donmigue V/Toast: HANDLE HIDE: 
android.widget.Toast$TN@adee711 mView=null
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue                     
D/ViewRootImpl@c39e34d[Toast]: setView = android.widget.LinearLayout@375c076 
TM=true MM=false
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue V/Toast: Text: Dorr in 
android.widget.Toast$TN@adee711
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.096 7910-7910/com.example.donmigue E/GraphicExt: 
GraphicExtModuleLoader::CreateGraphicExtInstance false
//-----------------------------------
2020-08-02 08:43:40.097 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: Relayout returned: old=(0,55,720,1436) new= 
(230,714,490,791) req=(260,77)0 dur=19 res=0x7 s={true 3939788800} ch=true
2020-08-02 08:43:40.100 7910-7942/com.example.donmigue D/OpenGLRenderer: 
createReliableSurface : 0xbaba46c0(0xead46800)
2020-08-02 08:43:40.106 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0x0 -> 0xd6e49580
2020-08-02 08:43:40.109 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.110 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue 
D/ViewRootImpl@630eeec[PopResetEmail]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
prepareNavigationBarInfo() DecorView@a03932b[PopResetEmail]
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
getNavigationBarColor() -855310
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.134 7910-7910/com.example.donmigue E/ViewRootImpl: 
sendUserActionEvent() mView returned.
//-----------------------------------
2020-08-02 08:43:40.138 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0xd6e49580 -> 0xb8fc7640
2020-08-02 08:43:40.140 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: MSG_RESIZED: frame=(230,714,490,791) ci= 
(0,0,0,0) 
vi=(0,0,260,77) or=1
2020-08-02 08:43:40.140 7910-7942/com.example.donmigue I/GPUD:                                                                                                                                             
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.142 7910-7942/com.example.donmigue I/chatty: 
uid=10536(com.example.donmigue) RenderThread identical 3 lines

Advertisement

Answer

If the task is unsuccessful, calling task.getException() will give you details about what went wrong. So you’ll want to show/log that with something like:

user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener <Void> () {
    @Override
    public void onComplete (@NonNull Task <Void> task) {
        if (task.isSuccessful ()) {
            Toast.makeText (PopResetEmail.this, "Mail Updated", Toast.LENGTH_SHORT).show ();
        } else {
            Exception e = task.getException();
            Toast.makeText (PopResetEmail.this, "Error updating email: "+e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.w("updateEmail", "Unable to update email", e);
        }
        pDialog.dismiss ();
    }
});

That usually is enough to troubleshoot.

Also see:

Advertisement