in CredentialsQuickstart/app/src/main/java/com/google/example/credentialsbasic/MainActivity.java [153:197]
private void saveCredentialClicked() {
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create a Credential with the user's email as the ID and storing the password. We
// could also add 'Name' and 'ProfilePictureURL' but that is outside the scope of this
// minimal sample.
Log.d(TAG, "Saving Credential:" + email + ":" + anonymizePassword(password));
final Credential credential = new Credential.Builder(email)
.setPassword(password)
.build();
showProgress();
// NOTE: this method unconditionally saves the Credential built, even if all the fields
// are blank or it is invalid in some other way. In a real application you should contact
// your app's back end and determine that the credential is valid before saving it to the
// Credentials backend.
showProgress();
mCredentialsClient.save(credential).addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
showToast("Credential saved.");
hideProgress();
return;
}
Exception e = task.getException();
if (e instanceof ResolvableApiException) {
// The first time a credential is saved, the user is shown UI
// to confirm the action. This requires resolution.
ResolvableApiException rae = (ResolvableApiException) e;
resolveResult(rae, RC_SAVE);
} else {
// Save failure cannot be resolved.
Log.w(TAG, "Save failed.", e);
showToast("Credential Save Failed");
hideProgress();
}
}
});
}