Get Top Contacted data in android

1k views Asked by At

I am trying to get the top contacted call log details in android. Say if the person A has been contacted for 5 times, B has been contacted for 3 times and C 10 times. Now, I want to extract C and A as my top contacted persons in my phone.

Can any body explain me how to do this. I am able to get most recent call logs now.

I referred this, but no luck

How to get contacts with which the user talks often?

1

There are 1 answers

3
midhunhk On

I was able to do something similar in a different approach. In the Contacts API, there is a field called ContactsContract.Contacts.TIMES_CONTACTED which tells the number of times that contact has been contacted.

This approach is not related to the CallLogs API. User can clear the CallLogs, but not the times contacted.

  1. Check this link for developer notes on ContactsContract.Contacts.
  2. Check this link for an android library that I have created which can give you this implementation.ae-apps-library You would be looking for the class ContactManager. Once you fetch all the contacts, you need to sort based on the times contacted field to get your required list.

Edit: If you see the fetchAllContacts method in the ContactManager from the library, you can see how the data are read using the API. All you need to do would be to sort this list based on the timesContacted field by writing a Custom Comparator and sorting the list using that.