Home » Android » android – ContactsContract how to enumerate all available fields?

android – ContactsContract how to enumerate all available fields?

Posted by: admin June 15, 2020 Leave a comment

Questions:

In my application I need to give user opportinity to see/edit all available fields of ContactsContract.

How should I get/see all available fields – including any custom ones?

How to&Answers:

First get all of the names of people that exist in your phone:

Cursor phones = getContentResolver().query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null,
                    null,
                    null,
                    ContactsContract.Contacts.DISPLAY_NAME
                            + " COLLATE LOCALIZED ASC");
            while (phones.moveToNext()) {

                name = phones
                        .getString(phones
                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                namelist.add(name);
                String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                 number_list.add(phoneNumber);
            detaillist.put(name, phoneNumber);
            }
            phones.close();
}

Now get contact id and get other information like phone number, email id, address, organization by using contact id:

By doing this you can get all the fields of contacts-contract.

Answer:

This logs the name and value of all columns in all contact rows. Tested on Galaxy S6 with native contacts app. I needed it to find the column name that is used for custom SMS notification sound (sec_custom_alert).