Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'API Phone Number Hint, une bibliothèque fournie par les services Google Play, permet d'afficher les numéros de téléphone (basés sur la carte SIM) d'un utilisateur en tant qu'indice.
Voici les avantages de l'utilisation de l'indice de numéro de téléphone:
Aucune demande d'autorisation supplémentaire n'est requise
L'utilisateur n'a plus besoin de saisir manuellement le numéro de téléphone.
Aucun compte Google n'est requis.
Non directement associé aux flux de connexion ou d'inscription
Compatibilité plus étendue avec les versions d'Android par rapport à la saisie automatique
Fonctionnement
L'API Phone Number Hint utilise un PendingIntent pour lancer le flux. Une fois le PendingIntent lancé, une UI s'affiche, listant tous les numéros de téléphone (basés sur la carte SIM). L'utilisateur peut alors choisir de sélectionner un numéro de téléphone à utiliser ou d'annuler le parcours.
Le numéro de téléphone sélectionné sera ensuite mis à la disposition du développeur pour qu'il puisse le récupérer dans Intent.
Figure 1. UI et paramètres de l'indice de numéro de téléphone
Pour préparer votre application, procédez comme indiqué dans les sections suivantes.
Appelez SignInClient.getPhoneNumberHintIntent(), en transmettant l'objet GetPhoneNumberHintIntentRequest précédent, pour récupérer PendingIntent et lancer le flux d'indice de numéro de téléphone.
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);}}});
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/17 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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```"]]