Phone Selector API is used to detect phone numbers being used in the phone. Using this you can avoid manual input of Phone Number 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”
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.
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.
Github Link: https://github.com/introidx/phone-Selecter