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 8166277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:48:26+00:00 2026-06-06T19:48:26+00:00

I want to get some basic info of all contacts(I use api lvl 8).

  • 0

I want to get some basic info of all contacts(I use api lvl 8). Currently i use this code snippet

private List<ContactInfo> readContacts() {

    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, Phone.DISPLAY_NAME + " ASC");

    for (int i = 0; i < cur.getColumnCount(); i++) {

        Log.v("COlum", cur.getColumnName(i));

    }
    List<ContactInfo> temp = new ArrayList<ContactInfo>();
    if (cur.getCount() > 0) {

        while (cur.moveToNext()) {
            ContactInfo mContactInfo = new ContactInfo();
            String id = cur.getString(cur
                    .getColumnIndex(ContactsContract.Contacts._ID));
            mContactInfo.setId(Long.parseLong(id));
            String name = cur
                    .getString(cur
                            .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer
                    .parseInt(cur.getString(cur
                            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                mContactInfo.setmDisplayName(name);

                // get the <span class="IL_AD" id="IL_AD7">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));

                    mContactInfo.setmPhoneNumber(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 <span
                    // class="IL_AD" id="IL_AD9">addresses</span>
                    // if the email addresses were stored in an array
                    String email = emailCur
                            .getString(emailCur
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));

                    mContactInfo.setmEmail(email);
                }
                emailCur.close();

                temp.add(mContactInfo);
            }
        }
    }
    return temp;

}

and pass to custom adapter (extended baseadapter). I get contact’s photo using:

public static Bitmap loadContactPhoto(ContentResolver cr, long id) {
        Uri uri = ContentUris.withAppendedId(
                ContactsContract.Contacts.CONTENT_URI, id);
        InputStream input = openContactPhotoInputStream1(cr, uri);
        if (input == null) {
            return null;
        }
        return BitmapFactory.decodeStream(input);
}

I tested on my phone with 2x contacts (had photo). I took ~ 10s to fetch all contact at 1st runtime. I try force close in application settings and run again. This time it took ~2s to get data.So i want to know the most effective way to get contacts info.

I found some similar SO questions but they dont need photo. contacts in android
I tried use cursor and cursor adapter but i dont know what query to get photo_uri + contact name at the same time.

Edit: i removed all getColumnIndex i can out of loop and project only column i want. The performance is better(10s => 5s).

What i want to know :
Better way to query info and set to my ContactInfo model or the query which get name, phone number, email, photo at the same time to pass to cursor adapter.

Thanks in advance

  • 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-06T19:48:28+00:00Added an answer on June 6, 2026 at 7:48 pm

    I changed to CusorAdapter and use ContactsPhotoLoader from Contacts app and performance is improved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a basic CFTree with some string info in Objective-C. This
Using Doctrine 2 I want to get some users that are contacts of another
I'm just starting to get my hands dirty with some basic jQuery. I want
I am new to Arquillian and want to get some basic testing working (inject
I want to get some useful information from NSError . If I print out
I want to get some images from a movie and make a gif. What
I want to get some text from a PHP page into an Android application.
I want to get some images from a flash webpage and I got the
i am developing and application in which i want to get some feeds from
I am using http://lite.facebook.com And i want to get some data from my account.

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.