How to Use Phone Selector API in Android?
Last Updated :
23 Jul, 2025
Phone Selector API is used to detect phone numbers being used in the phone. Using this you can avoid manual input of Phone Numbers by users and prompt them to choose the desired number. A sample image is given below to get an idea about what we are going to do in this article.
Note that we are going to implement this project using the Kotlin language.

Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Note that select Kotlin as the programming language
Step 2: Add dependency to the build.gradle file and click "sync now"
dependencies {
...
implementation ("com.google.android.gms:play-services-auth:20.5.0")
}
Step 3: Working with the activity_main.xml file
Go to the activity_main.xml file and refer to the following code. For simplicity, we are using just a TextView to show the number after selection. Below is the code for the activity_main.xml file.
activity_main.xml:
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Open"
app:layout_constraintLeft_toLeftOf="@id/tv1"
app:layout_constraintTop_toBottomOf="@id/tv1" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 4: Inside MainActivity.kt write the following code
To retrieve the Phone Number hints, first, configure the hint selector dialog by creating a HintRequest object. Then, pass the HintRequest object to credentialsClient.getHintPickerIntent() to get an intent to prompt the user to choose a phone number. Finally, start the intent with startIntentSenderForResult().
onActivityResult() method will help to get the number user has selected and then you can write the next logic to continue with your app.
MainActivity.kt:
Kotlin
@file:Suppress("DEPRECATION")
package org.geeksforgeeks.demo
import android.content.Intent
import android.content.IntentSender
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.auth.api.credentials.Credential
import com.google.android.gms.auth.api.credentials.Credentials
import com.google.android.gms.auth.api.credentials.CredentialsApi
import com.google.android.gms.auth.api.credentials.CredentialsOptions
import com.google.android.gms.auth.api.credentials.HintRequest
class MainActivity : AppCompatActivity() {
private lateinit var phoneSelectorButton: Button
private lateinit var selectedPhoneNumberTextView: TextView
companion object {
var CREDENTIAL_PICKER_REQUEST = 1
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
phoneSelectorButton = findViewById(R.id.btn_open)
selectedPhoneNumberTextView = findViewById(R.id.tv1)
// set on click listener to button
// to open the phone selector dialog
phoneSelectorButton.setOnClickListener {
phoneSelection()
}
}
private fun phoneSelection() {
// To retrieve the Phone Number hints, first, configure
// the hint selector dialog by creating a HintRequest object.
val hintRequest = HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build()
val options = CredentialsOptions.Builder()
.forceEnableSaveDialog()
.build()
// Then, pass the HintRequest object to
// credentialsClient.getHintPickerIntent()
// to get an intent to prompt the user to
// choose a phone number.
val credentialsClient = Credentials.getClient(this, options)
val intent = credentialsClient.getHintPickerIntent(hintRequest)
try {
startIntentSenderForResult(
intent.intentSender,
CREDENTIAL_PICKER_REQUEST, null, 0, 0, 0, Bundle()
)
} catch (e: IntentSender.SendIntentException) {
e.printStackTrace()
}
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CREDENTIAL_PICKER_REQUEST && resultCode == RESULT_OK) {
// get data from the dialog which is of type Credential
val credential: Credential? = data?.getParcelableExtra(Credential.EXTRA_KEY)
// set the received data t the text view
credential?.apply {
selectedPhoneNumberTextView.text = credential.id
}
} else if (requestCode == CREDENTIAL_PICKER_REQUEST && resultCode == CredentialsApi.ACTIVITY_RESULT_NO_HINTS_AVAILABLE) {
Toast.makeText(this, "No phone numbers found", Toast.LENGTH_LONG).show()
}
}
}
Output:
Refer to the following Github Link to get the entire code: Phone-Selector-API-in-Android