Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
La API de Phone Number Hint, una biblioteca con tecnología de los Servicios de Google Play, proporciona una forma sencilla de mostrar los números de teléfono (basados en SIM) de un usuario como una sugerencia.
Entre los beneficios de usar la sugerencia de número de teléfono, se incluyen los siguientes:
No se necesitan solicitudes de permisos adicionales.
Elimina la necesidad de que el usuario escriba manualmente el número de teléfono.
No se necesita una Cuenta de Google
No están directamente vinculados a flujos de trabajo de acceso o registro.
Compatibilidad más amplia con versiones de Android en comparación con Autocompletar
Cómo funciona
La API de Phone Number Hint usa un PendingIntent para iniciar el flujo. Una vez que se haya iniciado el PendingIntent, se le mostrará al usuario una IU con todos los números de teléfono (basados en SIM). Luego, el usuario puede elegir seleccionar un número de teléfono que le gustaría usar o cancelar el flujo.
Luego, el número de teléfono seleccionado estará disponible para que el desarrollador lo recupere de Intent.
Figura 1: IU y configuración de la sugerencia de número de teléfono
Para preparar tu app, completa los pasos que se indican en las siguientes secciones.
Cómo solicitar una sugerencia de número de teléfono
Llama a SignInClient.getPhoneNumberHintIntent() y pasa el objeto GetPhoneNumberHintIntentRequest anterior para recuperar el PendingIntent y, así, iniciar el flujo de sugerencias de números de teléfono.
Kotlin
valphoneNumberHintIntentResultLauncher=...Identity.getSignInClient(activity).getPhoneNumberHintIntent(request).addOnSuccessListener{result:PendingIntent->try{phoneNumberHintIntentResultLauncher.launch(IntentSenderRequest.Builder(result).build())}catch(e:Exception){Log.e(TAG,"Launching the PendingIntent failed")}}.addOnFailureListener{Log.e(TAG,"Phone Number Hint failed")}
Java
ActivityResultLauncherphoneNumberHintIntentResultLauncher=...Identity.getSignInClient(activity).getPhoneNumberHintIntent(request).addOnSuccessListener(result->{try{phoneNumberHintIntentResultLauncher.launch(result.getIntentSender());}catch(Exceptione){Log.e(TAG,"Launching the PendingIntent failed",e);}}).addOnFailureListener(e->{Log.e(TAG,"Phone Number Hint failed",e);});
valphoneNumberHintIntentResultLauncher=registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()){result->try{valphoneNumber=Identity.getSignInClient(activity).getPhoneNumberFromIntent(result.data)}catch(e:Exception){Log.e(TAG,"Phone Number Hint failed")}}
Java
ActivityResultLauncherphoneNumberHintIntentResultLauncher=registerForActivityResult(newActivityResultContracts.StartActivityForResult(),newActivityResultCallback(){@OverridepublicvoidonActivityResult(ActivityResultresult){try{StringphoneNumber=Identity.getSignInClient(activity).getPhoneNumberFromIntent(result.getData());}catch{Log.e(TAG,"Phone Number Hint failed",e);}}});
El contenido y las muestras de código que aparecen en esta página están sujetas a las licencias que se describen en la Licencia de Contenido. Java y OpenJDK son marcas registradas de Oracle o sus afiliados.
Última actualización: 2025-08-17 (UTC)
[[["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-08-17 (UTC)"],[],[],null,["# Phone Number Hint\n\nThe Phone Number Hint API, a library powered by [Google Play services](https://developers.google.com/android),\nprovides a frictionless way to show a user's (SIM-based) phone numbers as a\nhint.\n\nThe benefits to using Phone Number Hint include the following:\n\n- No additional permission requests are needed\n- Eliminates the need for the user to manually type in the phone number\n- No Google Account is needed\n- Not directly tied to sign-in or sign-up workflows\n- Wider support for Android versions compared to Autofill\n\nHow it works\n------------\n\nThe Phone Number Hint API utilizes a [`PendingIntent`](/reference/android/app/PendingIntent)\nto initiate the flow. Once the PendingIntent has been launched the user will be\npresented with a UI, listing out all (SIM-based) phone numbers. The user can\nthen choose to select a phone number they would like to use or cancel the flow.\nThe selected phone number will then be made available to the developer to\nretrieve from the [`Intent`](/reference/android/content/Intent).\n**Figure 1.** Phone Number Hint UI and Settings\n\nTo prepare your app, complete the steps in the following sections.\n\nConfigure your app\n------------------\n\nAdd the [Google Play services](https://developers.google.com/android)\ndependency for the Phone Number Hint API to your\n[module's Gradle build file](/studio/build#module-level),\nwhich is commonly `app/build.gradle`: \n\n apply plugin: 'com.android.application'\n\n ...\n\n dependencies {\n implementation 'com.google.android.gms:play-services-auth:21.4.0'\n }\n\n### Create a GetPhoneNumbeHintIntentRequest object\n\nStart by creating a [`GetPhoneNumberHintIntentRequest`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetPhoneNumberHintIntentRequest) object using the\nprovided [`GetPhoneNumberHintIntentRequest.Builder()`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetPhoneNumberHintIntentRequest.Builder)\nmethod. This request object can then be used to get an `Intent` to start the\nPhone Number Hint flow. \n\n### Kotlin\n\n```kotlin\nval request: GetPhoneNumberHintIntentRequest = GetPhoneNumberHintIntentRequest.builder().build()\n```\n\n### Java\n\n```java\nGetPhoneNumberHintIntentRequest request = GetPhoneNumberHintIntentRequest.builder().build();\n```\n\n### Requesting Phone Number Hint\n\nCall [`SignInClient.getPhoneNumberHintIntent()`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getPhoneNumberHintIntent(com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest)),\npassing in the previous `GetPhoneNumberHintIntentRequest` object,\nto retrieve the `PendingIntent` to initiate the Phone Number Hint flow. \n\n### Kotlin\n\n```kotlin\nval phoneNumberHintIntentResultLauncher = ...\n\nIdentity.getSignInClient(activity)\n.getPhoneNumberHintIntent(request)\n.addOnSuccessListener { result: PendingIntent -\u003e\n try {\n phoneNumberHintIntentResultLauncher.launch(\n IntentSenderRequest.Builder(result).build()\n )\n } catch (e: Exception) {\n Log.e(TAG, \"Launching the PendingIntent failed\")\n }\n}\n.addOnFailureListener {\n Log.e(TAG, \"Phone Number Hint failed\")\n}\n```\n\n### Java\n\n```java\nActivityResultLauncher phoneNumberHintIntentResultLauncher = ...\n\nIdentity.getSignInClient(activity)\n .getPhoneNumberHintIntent(request)\n .addOnSuccessListener( result -\u003e {\n try {\n phoneNumberHintIntentResultLauncher.launch(result.getIntentSender());\n } catch(Exception e) {\n Log.e(TAG, \"Launching the PendingIntent failed\", e);\n }\n })\n .addOnFailureListener(e -\u003e {\n Log.e(TAG, \"Phone Number Hint failed\", e);\n });\n```\n\n### Retrieving the phone number\n\nPass in the `Intent` to [`SignInClient.getPhoneNumberFromIntent`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getPhoneNumberFromIntent(android.content.Intent))\nto retrieve the phone number. \n\n### Kotlin\n\n```kotlin\nval phoneNumberHintIntentResultLauncher =\nregisterForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result -\u003e\n try {\n val phoneNumber = Identity.getSignInClient(activity).getPhoneNumberFromIntent(result.data)\n } catch(e: Exception) {\n Log.e(TAG, \"Phone Number Hint failed\")\n }\n }\n```\n\n### Java\n\n```java\nActivityResultLauncher phoneNumberHintIntentResultLauncher =\n registerForActivityResult(\n new ActivityResultContracts.StartActivityForResult(),\n new ActivityResultCallback() {\n @Override\n public void onActivityResult(ActivityResult result) {\n try {\n String phoneNumber = Identity.getSignInClient(activity).getPhoneNumberFromIntent(result.getData());\n } catch {\n Log.e(TAG, \"Phone Number Hint failed\", e);\n }\n }\n });\n```"]]