Search code examples
javaandroidandroid-contactsphone-number

Android get all contacts telephone number in ArrayList


I am trying to save all contacts telephone numbers in an ArrayList but I cant find a way how. Is there a way to get them instead of picking them one by one with ContactsContract?


Solution

  • Try this:

    Cursor managedCursor = getContentResolver()
        .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
         new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER}, null, null,  Phone.DISPLAY_NAME + " ASC");
    

    And by traversing through the cursor, you can store all this data in any data structure of your choice.