Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Después de que los usuarios accedan, creen cuentas o cambien las contraseñas correctamente, permite
que almacenen sus credenciales para automatizar futuras autenticaciones en tu app
Crea un objeto Credential que contenga la información de acceso de un usuario. Para
por ejemplo, para permitir que los usuarios almacenen sus credenciales después de acceder con
sus contraseñas:
Luego, llama a CredentialsClient.save() para guardar las contraseñas
credenciales. Si la llamada a CredentialsClient.save() no se envía de inmediato
correctamente, las credenciales pueden ser nuevas, en cuyo caso el usuario debe confirmar
la solicitud de guardado. Resuelve el ResolvableApiException con
startResolutionForResult() para solicitar la confirmación del usuario.
Si el usuario elige no guardar las credenciales, no se le volverá a solicitar que
guardar las credenciales de cualquier cuenta para la app. Si llamas
CredentialsClient.save() después de que un usuario inhabilitó la función, su resultado tendrá un
código de estado de CANCELED. El usuario puede aceptar la invitación más tarde desde la consola
App de Configuración, en la sección Smart Lock para contraseñas. El usuario debe habilitar
el guardado de credenciales de todas las cuentas, el cual se te solicitará que las guardes la próxima vez.
mCredentialsClient.save(credential).addOnCompleteListener(newOnCompleteListener<Void>(){@OverridepublicvoidonComplete(@NonNullTask<Void>task){if(task.isSuccessful()){Log.d(TAG,"SAVE: OK");Toast.makeText(activity,"Credentials saved",Toast.LENGTH_SHORT).show();return;}Exceptione=task.getException();if(einstanceofResolvableApiException){// Try to resolve the save request. This will prompt the user if// the credential is new.ResolvableApiExceptionrae=(ResolvableApiException)e;try{rae.startResolutionForResult(this,RC_SAVE);}catch(IntentSender.SendIntentExceptionexception){// Could not resolve the requestLog.e(TAG,"Failed to send resolution.",exception);Toast.makeText(activity,"Save failed",Toast.LENGTH_SHORT).show();}}else{// Request has no resolutionToast.makeText(activity,"Save failed",Toast.LENGTH_SHORT).show();}}});</pre>
@OverridepublicvoidonActivityResult(intrequestCode,intresultCode,Intentdata){super.onActivityResult(requestCode,resultCode,data);// ...if(requestCode==RC_SAVE){if(resultCode==RESULT_OK){Log.d(TAG,"SAVE: OK");Toast.makeText(this,"Credentials saved",Toast.LENGTH_SHORT).show();}else{Log.e(TAG,"SAVE: Canceled by user");}}// ...}
Cuando guardas credenciales de contraseñas usando Smart Lock en dispositivos con Android O
o una versión posterior, Smart Lock usa por su cuenta el diálogo de confirmación nativo de Autocompletar
cuando sea posible. (Ten en cuenta que las credenciales guardadas con Autocompletar con
Google se comparten bidireccionalmente con Smart Lock para contraseñas).
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-25 (UTC)"],[[["\u003cp\u003eSmart Lock for Passwords is deprecated; migrate to Credential Manager for enhanced security and user experience with passkey, password, and federated identity support.\u003c/p\u003e\n"],["\u003cp\u003eStore user credentials after sign-in, account creation, or password changes to enable automated authentication in your app using Credential Manager.\u003c/p\u003e\n"],["\u003cp\u003eCreate \u003ccode\u003eCredential\u003c/code\u003e objects with user sign-in information, including email, password (securely), account type, and profile details, before saving them with \u003ccode\u003eCredentialsClient.save()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHandle user confirmation for new credentials using \u003ccode\u003eResolvableApiException\u003c/code\u003e and \u003ccode\u003estartResolutionForResult()\u003c/code\u003e to ensure smooth credential saving.\u003c/p\u003e\n"],["\u003cp\u003eRetrieve stored credentials using \u003ccode\u003eCredentialsClient.request()\u003c/code\u003e for seamless user authentication within your app.\u003c/p\u003e\n"]]],[],null,["# Store a user's credentials\n\n| **Deprecated:** Smart Lock for Passwords is deprecated. To ensure the continued security and usability of your app, [migrate to\n| Credential Manager](https://developer.android.com/training/sign-in/passkeys/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.\n\nAfter users successfully sign in, create accounts, or change passwords, allow\nthem to store their credentials to automate future authentication in your app.\n\nBefore you begin\n----------------\n\n[Configure an Android Studio project](/identity/smartlock-passwords/android/get-started).\n\nStore credentials\n-----------------\n\nCreate a `Credential` object containing a user's sign-in information. For\nexample, to let users store their credentials after successfully signing in with\ntheir passwords: \n\n Credential credential = new Credential.Builder(email)\n .setPassword(password) // Important: only store passwords in this field.\n // Android autofill uses this value to complete\n // sign-in forms, so repurposing this field will\n // likely cause errors.\n .build();\n\nOr, for example, after users successfully\n[sign in with their Google account](/identity/sign-in/android/people): \n\n GoogleSignInAccount gsa = signInTask.getResult();\n Credential credential = new Credential.Builder(gsa.getEmail())\n .setAccountType(IdentityProviders.GOOGLE)\n .setName(gsa.getDisplayName())\n .setProfilePictureUri(gsa.getPhotoUrl())\n .build();\n\nThen, call [`CredentialsClient.save()`](/android/reference/com/google/android/gms/auth/api/credentials/CredentialsClient#save(com.google.android.gms.auth.api.credentials.Credential)) to save users'\ncredentials. If the call to `CredentialsClient.save()` is not immediately\nsuccessful, the credentials might be new, in which case the user must confirm\nthe save request. Resolve the `ResolvableApiException` with\n`startResolutionForResult()` to prompt the user for confirmation.\n\nIf the user chooses not to save credentials, the user won't be prompted again to\nsave any account's credentials for the app. If you call\n`CredentialsClient.save()` after a user has opted out, its result will have a\nstatus code of [`CANCELED`](/android/reference/com/google/android/gms/common/api/CommonStatusCodes#CANCELED). The user can opt in later from the Google\nSettings app, in the Smart Lock for Passwords section. The user must enable\ncredential saving for all accounts to be prompted to save credentials next time. \n\n mCredentialsClient.save(credential).addOnCompleteListener(\n new OnCompleteListener\u003cVoid\u003e() {\n @Override\n public void onComplete(@NonNull Task\u003cVoid\u003e task) {\n if (task.isSuccessful()) {\n Log.d(TAG, \"SAVE: OK\");\n Toast.makeText(activity, \"Credentials saved\", Toast.LENGTH_SHORT).show();\n return;\n }\n\n Exception e = task.getException();\n if (e instanceof ResolvableApiException) {\n // Try to resolve the save request. This will prompt the user if\n // the credential is new.\n ResolvableApiException rae = (ResolvableApiException) e;\n try {\n rae.startResolutionForResult(this, RC_SAVE);\n } catch (IntentSender.SendIntentException exception) {\n // Could not resolve the request\n Log.e(TAG, \"Failed to send resolution.\", exception);\n Toast.makeText(activity, \"Save failed\", Toast.LENGTH_SHORT).show();\n }\n } else {\n // Request has no resolution\n Toast.makeText(activity, \"Save failed\", Toast.LENGTH_SHORT).show();\n }\n }\n });\u003c/pre\u003e\n\n @Override\n public void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n\n // ...\n\n if (requestCode == RC_SAVE) {\n if (resultCode == RESULT_OK) {\n Log.d(TAG, \"SAVE: OK\");\n Toast.makeText(this, \"Credentials saved\", Toast.LENGTH_SHORT).show();\n } else {\n Log.e(TAG, \"SAVE: Canceled by user\");\n }\n }\n\n // ...\n\n }\n\nAfter storing credentials, retrieve them by calling\n[`CredentialsClient.request()`](/android/reference/com/google/android/gms/auth/api/credentials/CredentialsClient#request(com.google.android.gms.auth.api.credentials.CredentialRequest)).\n\nTargeting Android O and above\n-----------------------------\n\nWhen you save password credentials using Smart Lock on devices running Android O\nor newer, Smart Lock uses the native autofill confirmation dialog over its own\ndialog whenever possible. (Note that credentials saved using Autofill with\nGoogle are bi-directionally shared with Smart Lock for Passwords.)"]]