- Mastering Firebase for Android Development
- Ashok Kumar S
- 85字
- 2021-06-18 18:49:22
Anonymous Authentication
The name clearly states that the application allows users to access the application's features by providing a temporary anonymous identity. We need to enable anonymous login in the Firebase console. Next, the anonymousSignIn method calls the signInAnonymously() method of the FirebaseAuth instance:
public void anonymousSignIn() {
FirebaseAuth.signInAnonymously()
.addOnCompleteListener(this,
new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(AnonAuthActivity.this,
"Authentication failed. "
+ task.getException(),
Toast.LENGTH_SHORT).show();
} else {
softButton.setText("Create an Account");
buttonMode = CREATE_MODE;
}
}
});
}