Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:13:18+00:00 2026-06-05T12:13:18+00:00

I am trying to access the contact name number and email ID using this

  • 0

I am trying to access the contact name number and email ID using this code :

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;

public class GetAllDatas extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    readContacts();
}   

private void readContacts() {
    // TODO Auto-generated method stub

    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
           null, null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
            String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                System.out.println("name : " + name + ", ID : " + id);

                    // get the <span id="IL_AD1" class="IL_AD">phone number</span>


                Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                       ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                       new String[]{id}, null);
                while (pCur.moveToNext()) {
                      String phone = pCur.getString(
                             pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                      System.out.println("phone" + phone);
                }
                pCur.close();

                // get email and type


                Cursor emailCur = cr.query(
                         ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                         null,
                         ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
                         new String[]{id}, null);
                 while (emailCur.moveToNext()) {
                     // This would allow you get several email addresses
                         // if the email addresses were stored in an array
                     String email = emailCur.getString(
                                   emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                     String emailType = emailCur.getString(
                                   emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));

                   System.out.println("Email " + email + " Email Type : " + emailType);
                 }
                 emailCur.close();
            }
        }
    }

}
    }

When I run this code nothing would be displayed in my activity.

I need to access Contact name, number and email ID from my entire contact list on the activity window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:13:19+00:00Added an answer on June 5, 2026 at 12:13 pm

    Check with this

       package stack.examples;
    
    import java.util.ArrayList;
    import android.app.Activity;
    import android.content.ContentResolver;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.provider.ContactsContract.CommonDataKinds.Email;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    
    public class StackOverFlowGetContactsActivity extends Activity {
    
        ListView lvItem;
        private Button btnAdd;
        String displayName="", emailAddress="", phoneNumber="";
        ArrayList<String> contactlist=new ArrayList<String>();
        ArrayAdapter<String> itemAdapter;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
           lvItem = (ListView)this.findViewById(R.id.listView_items);  
           btnAdd = (Button)this.findViewById(R.id.btnAddItem);
           itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,contactlist);
           lvItem.setAdapter(itemAdapter);
           btnAdd.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   readContacts();
               }
           });
        }
    
        private void readContacts()
        {
            ContentResolver cr =getContentResolver();
            Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            while (cursor.moveToNext()) 
            {
                displayName="";emailAddress=""; phoneNumber="";
                displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));       
                String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                Cursor emails = cr.query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + id, null, null);
                while (emails.moveToNext()) 
                { 
                    emailAddress = emails.getString(emails.getColumnIndex(Email.DATA));
                    break;
                }
                emails.close();
                if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
                {
                    Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null);
                    while (pCur.moveToNext()) 
                    {
                         phoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        break;
                    }
                    pCur.close();
                }
                    contactlist.add("DisplayName: "+displayName+", PhoneNumber: "+phoneNumber+", EmailAddress: "+ emailAddress+"\n");
                    itemAdapter.notifyDataSetChanged();
            }
            cursor.close(); 
        }
    }
    

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ListView
            android:id="@+id/listView_items"
            android:layout_width="match_parent"
            android:layout_height="288dp"
            android:layout_weight="0.03" >
    
        </ListView>
    
        <Button
            android:id="@+id/btnAddItem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.01"
            android:text="@string/add" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download an image using this code: from urllib import urlretrieve urlretrieve('http://gdimitriou.eu/wp-content/uploads/2008/04/google-image-search.jpg',
I am trying to auto email a report from access using VBA in a
I am trying to access the group name of all entries in my contact
When trying to access data-onload using $(#index).data(onload) I get back 'undefined' : <script type=text/html>
I am trying to access some assets on azure from flash. This requires a
I am trying to get the contact's phone number after I have retrieved their
I am just tring to access the contact Content Provider. for that i wrote
While trying to access the contacts in Windows phone as detailed in this official
I've been trying to access the NHS API using different methods to read in
I've been trying to access some XML, which looks like this: <feed xmlns:s=http://syndication.nhschoices.nhs.uk/services xmlns=http://www.w3.org/2005/Atom>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.