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

  • Home
  • SEARCH
  • 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 5981437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:56:37+00:00 2026-05-22T21:56:37+00:00

I want to display all native contacts in a list and make user to

  • 0

I want to display all native contacts in a list and make user to add contacts from the list (Multiple contacts)to my application database.How to dothis can any one give me idea or share some code..
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-05-22T21:56:38+00:00Added an answer on May 22, 2026 at 9:56 pm

    I used this code on Android 2.1. It pulls down anyone who has a phone number (as defined by the String SELECTION variable) and returns a List of type Person. Person is an object that held the name and phone number of the user. You will have to implement a Person object in order to use this code, but it works perfectly:

    public List<Person> getContactList(){
            ArrayList<Person> contactList = new ArrayList<Person>();
    
            Uri contactUri = ContactsContract.Contacts.CONTENT_URI;
            String[] PROJECTION = new String[] {
                    ContactsContract.Contacts._ID,
                    ContactsContract.Contacts.DISPLAY_NAME,
                    ContactsContract.Contacts.HAS_PHONE_NUMBER,
            };
            String SELECTION = ContactsContract.Contacts.HAS_PHONE_NUMBER + "='1'";
            Cursor contacts = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, PROJECTION, SELECTION, null, null);
    
    
            if (contacts.getCount() > 0)
            {
                while(contacts.moveToNext()) {
                    Person aContact = new Person();
                    int idFieldColumnIndex = 0;
                    int nameFieldColumnIndex = 0;
                    int numberFieldColumnIndex = 0;
    
                    String contactId = contacts.getString(contacts.getColumnIndex(ContactsContract.Contacts._ID));
    
                    nameFieldColumnIndex = contacts.getColumnIndex(PhoneLookup.DISPLAY_NAME);
                    if (nameFieldColumnIndex > -1)
                    {
                        aContact.setName(contacts.getString(nameFieldColumnIndex));
                    }
    
                    PROJECTION = new String[] {Phone.NUMBER};
                    final Cursor phone = managedQuery(Phone.CONTENT_URI, PROJECTION, Data.CONTACT_ID + "=?", new String[]{String.valueOf(contactId)}, null);
                    if(phone.moveToFirst()) {
                        while(!phone.isAfterLast())
                        {
                            numberFieldColumnIndex = phone.getColumnIndex(Phone.NUMBER);
                            if (numberFieldColumnIndex > -1)
                            {
                                aContact.setPhoneNum(phone.getString(numberFieldColumnIndex));
                                phone.moveToNext();
                                TelephonyManager mTelephonyMgr;
                                mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                                if (!mTelephonyMgr.getLine1Number().contains(aContact.getPhoneNum()))
                                {
                                    contactList.add(aContact);  
                                }
                            }
                        }
                    }
                    phone.close();
                }
    
                contacts.close();
            }
    
            return contactList;
        }
    

    EDIT: A rudimentary Person class:

    public class Person {
        String myName = "";
        String myNumber = "";
    
        public String getName() {
            return myName;
        }
    
        public void setName(String name) {
            myName = name;
        }
    
        public String getPhoneNum() {
            return myNumber;
        }
    
        public void setPhoneNum(String number) {
            myNumber = number;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display all records from table of current autorized user in my
I want to display all records from database in gridview when pageload and also
I have a list of company names, and want to display all the names
I want to display all the ToolTips in my web page is user defined,
I want to display all lines from one which match regular expression if I
I want to display all the pages the user is admin of with the
I want to display all elements from a ListBox to a TextBox. I'm not
I want to display all the files from a selected folder.. ie files from
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
i want to display all posts in Post table with say id=5 ...... controller

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.