Retrieving contacts in ListView in Android using Content Provider

In this tutorial we will learn about how to Retrieving contacts in ListView in Android. We will use Content Provider to fetch contact details and show in Listview. We read only user name and mobile number from the contacts.

Step-1 :  Add permission: Since we are accessing user contacts so we have to add contacts permission in our Manifest file.

Here we only added contact permission in Manifest file. We also need to ask user user for run time permission. We covered about this in one of the tutorial. For more about Runtime permission in Android you can check Android Runtime Permission  tutorials. We are using askForPermission()  method to check run time permission.

Step-2: Create an Activity  I have an Activity with the name of  ContactsActivity. Below is our layout file of Activity in which there is only a ListView that contains contacts of users.

Below is code of Java file. We have simply used Cursor to query the data and moveToNext() to move the cursor to next row.  ContactsContract.CommonDataKinds is a container that store personal information. such as phone number. Below is our code of ContactsActivity.java file.

This is all about Retrieving contacts in ListView in Android.

If you have doubts or facing any problems please let me know in the comment box I will happy to help you. You can check other tutorials as well.  If you only thinking about getting codes you can check this gist.

Login with Gooogle using Firebase in Android

JSON Parsing and display into RecyclerView using Volley Library

Android Login and Signup with PHP MySQL

Parse JSON data into Spinner in Android

Android show current location in Google Map using Google Maps Android API

Youtube channel integration in Android using YoutubePlayerView API

Google Places Autocomplete Services using Google Places API