0

I pulled contacts2.db from emulator(API 19) and checked contacts table. contacts table

It doesn't have display_name column.

However, after executing the following code,

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, REQUEST_CONTACT); 

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }

    if (requestCode == REQUEST_DATE) {
    ...

    } else if (requestCode == REQUEST_CONTACT && data != null) {
        Uri contactUri = data.getData();

        // Perform your query - the contactUri is like a "where" clause here
        Cursor c = getActivity().getContentResolver().query(contactUri
            , null
            , null
            , null
            , null);

        //cursor null check

        try {
            // Double-check that you actually got results
            if (c.getCount() == 0) {
                return;
            }
            c.moveToFirst();
            String[] names = c.getColumnNames();
        } finally {
            c.close();
        }
    }
}

When I checked names, the list of columns is

 sort_key
 photo_uri
 send_to_voicemail
 contact_status
 contact_status_label
 pinned
 display_name
 phonebook_label_alt
 phonebook_bucket
 contact_status_res_package
 photo_id
 in_default_directory
 custom_ringtone
 _id
 times_contacted
 phonebook_label
 lookup
 display_name_alt
 phonetic_name
 last_time_contacted
 contact_last_updated_timestamp
 has_phone_number
 in_visible_group
 is_user_profile
 display_name_source
 photo_file_id
 contact_status_ts
 phonebook_bucket_alt
 sort_key_alt
 contact_presence
 starred
 photo_thumb_uri
 contact_status_icon
 contact_chat_capability
 phonetic_name_style
 name_raw_contact_id

It includes display_name column. How is it possible??

JE Bang
  • 1
  • 1

1 Answers1

0

Do you know about ContactsContract.

From the docs about a Contract class

The class establishes a contract between the provider and other applications by ensuring that the provider can be correctly accessed even if there are changes to the actual values of URIs, column names, and so forth.

So the display_name column is translated to actual display_name by the provider and request is made. The cursor is then translated as per definition in ContactsContract.

Birendra Singh
  • 842
  • 11
  • 19
  • I know ContactsContract... Did you check the image which I uploaded? You can see it when you click "contacts table" in the first line. I used SQLite tool to read contacts2.db and the tool showed me the column list. – JE Bang Jul 12 '17 at 01:13
  • Do you want to say that there is no such a column which can be mapped to `display_name`? – Birendra Singh Jul 12 '17 at 04:02
  • yes. I can see columns of Contacts table in "Columns" table in the following site:https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html. no display_name! – JE Bang Jul 12 '17 at 06:43
  • display_name is in raw_contacts table. – JE Bang Jul 12 '17 at 06:50
  • What about [this](https://developer.android.com/reference/android/provider/ContactsContract.ContactNameColumns.html)? – Birendra Singh Jul 12 '17 at 07:41
  • It is duty of content provider to give you all the data in the columns it promises to give. How it does is a matter of implementation. If Contacts Provider promises you to give `display_name` then it is the duty of Contacts Provider to implement the retrieval of `display_name'. Where it stores? How it gets? As I said is a matter of implementation of Contacts Provider. See [this answer](https://stackoverflow.com/a/6588402/5969624) to know hoe projection is being formed. This projection will be shot from device or internet, only content provider knows. – Birendra Singh Jul 12 '17 at 07:57