Android – how to get the contacts users often talk to?

Can I use contactscontract to get the contacts that users often talk to?

I know I can use calllog ContentProvider and try to solve this problem, but I wonder if there is a way to implement it

resolvent:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>