Android contact picker example

Introduction :

In this tutorial i am going to explain about Android contact picker example. While developing one of the application to the client i had the requirement to pick contact from the phone contact list to make call and send sms from the clients app. So i have digged through the internet and came up with below solution for Android contact picker example.

Implementation of Android contact picker example

Create new project

Create a new project and name the application as contact picker example. You can check how to create a new project in android studio article for creating the project step by step.

Add Permission In Android Manifest:

Once the project is created we need to add required permission in android manifest. For reading contacts from the android device we need READ_CONTACTS permission. So please add this permission in Android Manifest file.

Now the modified Android Manifest file is given below.

Modify Layout File:

Now in the activity_main.xml layout file i have added a button btnPickContact for picking the contact. And added two textviews with id tvContactName and tvContactNumber for showing the picked contactname and contact number. Below is the modified activity_main.xml layout file.

Implementing Android contact picker example

Now in the on btnPickContact onclick event create a new event with Intent.ACTION_PICK and start the activity. And in onActivityResult check the requestcode is matched and then the result code is RESULT_OK . Then you can get the URI of the selected contact by calling getData() on the data Intent parameter.

Once the URI is retrieved find the column index of contactnumber and contactname.Then query the uri and bind the contact details to textviews. Below is the entire main activity code for Android contact picker example


Now if you run the application you can see the below screen.

Output 1 of Android contact picker example

Screen 1 of Android contact picker example

While clicking on the Pick Contact button it will ask to choose the app to complete the action.

Output 2 of Android contact picker example

Screen 2 of Android contact picker example

After choosing contacts app,contact is picked and then information will be read and binded to textview.

Output 3 of Android contact picker example

Screen 3 of Android contact picker example

Hope you enjoyed Android contact picker example tutorial. You can post your queries & feedback in comment section.

Sourcecode of Android contact picker example


Leave a Reply

Your email address will not be published. Required fields are marked *