Reputation: 15
I have a problem here. I want to know whether the user has verified the email or not. If the user has verified the email by clicking on the link given, the application should automatically go to the homeScreen. Or else, the user may remain on the same page.
Below is a part of my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_email_verification);
emailVerify = findViewById(R.id.emailVerify);
final FirebaseUser user = auth.getCurrentUser();
Intent intent = getIntent();
name = intent.getStringExtra("name");
email = intent.getStringExtra("email");
password = intent.getStringExtra("password");
emailVerify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
user.sendEmailVerification().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
storeNewUsersData();
Toast.makeText(v.getContext(), "Verification email has been sent.", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: Email not sent " + e.getMessage());
}
});
//check whether the user has verified the email and go to homeScreen
}
});
}
Upvotes: 0
Views: 71
Reputation: 8867
Try this:
public void verifyEmail() {
if (firebaseAuth.getCurrentUser().isEmailVerified()) { //FirbaseUser must not be null!
Toast.makeText(view.getContext(), "Email has been verified.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(view.getContext(), "Email has not been verified.", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 2
Reputation: 519
https://www.youtube.com/watch?v=Wf7DDIaRYjk This tutorial maybe helpful I implemented mine from this.
Upvotes: 2