用户经常与之交谈的联系人

用户经常与之交谈的联系人

是否可以使用contactscontract获取用户经常与之交谈的联系人?
我知道我可以使用calllog contentprovider并尝试解决这个问题,但我想知道是否已经有一种方法可以做到这一点。

最佳答案

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();
            }

08-28 19:21