5

Is it possible using ContactsContract to get contacts with which the user talks often?

I know I can use the CallLog ContentProvider and try to figure that out, but I wanted to know if there is already a way to do it.

dors
  • 5,802
  • 8
  • 45
  • 71

1 Answers1

4

The number of times a contact has been contacted

ContactsContract.Contacts.times_contacted


            static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.STARRED,
                ContactsContract.Contacts.TIMES_CONTACTED,
                ContactsContract.Contacts.CONTACT_PRESENCE,
                ContactsContract.Contacts.PHOTO_ID,
                ContactsContract.Contacts.LOOKUP_KEY,
                ContactsContract.Contacts.HAS_PHONE_NUMBER,
            };

            String name_to_search = "John Doe";


            Cursor c = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, null, null, ContactsContract.Contacts.TIMES_CONTACTED);
            context.startManagingCursor(c);

            if (c.moveToNext())
            {
                String id = c.getString(0);
                ArrayList<String> phones = new ArrayList<String>();

                Cursor pCur = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
                while (pCur.moveToNext())
                {
                    phones.add(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
                    Log.i("", name_to_search+ " has the following phone number "+ pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
                } 
                pCur.close();   
            }
Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
  • Thanks, though it seems that this field is problematic: http://stackoverflow.com/questions/6749463/how-times-contacted-works-on-android. But this is what I asked for, so I'll mark it as the answer. – dors Aug 17 '13 at 15:24