All TalkersCode Topics

Follow TalkersCode On Social Media

How To Get Contact List In Android Programmatically

Last Updated : Jul 1, 2023

How To Get Contact List In Android Programmatically

In this article we will show you the solution of how to get contact list in android programmatically, phone Contacts are an extremely important source of data for everyone and hence accessing phone contacts is the basic feature for many applications like Truecaller to help the users and provide them a better experience in accessing phone contacts.

We always have a default application in our mobile to manage contacts but what will happen if we create our own application that will read all our saved contacts and will show them to the user.

We can use the particular application for backup of our contacts. So, in this tutorial, we are going to learn how to get contact list in android programmatically.

Step By Step Guide On How To Get Contact List In Android Programmatically :-

By Using Cursor Class

A cursor is a class that actually contains the result set for a query that was made against a database in Android.

This class contains an API that provides a feature to read the columns which were returned from the query, as well as helps to repeat over the rows of the result set.

<?xml version="1.0" encoding="utf-8"?>
    <!--Button to perform clicking event to
        access contacts list inside listView-->
        android:text="Click Here"
        android:textColor="#FFFFFF" />
    <!--ListView to show all saved contacts-->
        android:layout_below="@+id/Button" />
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
public class MainActivity extends AppCompatActivity {
    Cursor cursor;
    ListView listView;
    Button button;
    protected void onCreate(Bundle savedInstanceState) {
        // declaring listView using findViewById()
        listView = findViewById(;
        // declaring button using findViewById()
        button = findViewById(;
        // set OnClickListener() to the button
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // calling of getContacts()
    public void getContacts() {
        // create cursor and query the data
        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
                String[] data = {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone._ID};
        int[] to = {,};
                SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, data, to);
        // Calling setAdaptor() method to set created adapter
  1. In the first step you need to create new project in Android.
  2. Now u need to navigate to the app> manifests> AndroidManifest.xml file and kindly add below permission there to read contacts. <uses-permission android:name=”android.permission.READ_CONTACTS”></uses-permission>
  3. Now it’s the moment to design the basic layout of the application. So, kindly navigate to app > res > layout > activity_main.xml and paste the below-written code in the activity_main.xml file.
  4. Working with the file. Now u need to navigate to the app > java > package name > file. Below is actually the main code for the file.

Conclusion :-

This is the end of a pretty important tutorial in Android. Above was a basic example of How to get contact list in android with the help of a program/code. Later on, we will study more on Android topics.

I hope this article on how to get contact list in android programmatically helps you and the steps and method mentioned above are easy to follow and implement.