Android - How to get a contact from call log?

android call history by contact
add recent call to contacts android
my activity call history
android call log app
call history google
android call history time
old call history android
android call history missing

I am trying to get contacts from call log. I can get the contact numbers from main contacts using this code :

    public void getContacts(View view) {

    Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intentContact, 0);


public void onActivityResult(int requestCode, int resultCode, Intent intent)

    if (requestCode == 0)
        try {
        } catch(NullPointerException e) {
                 // Do nothing ;)


protected String getContactInfo(Intent intent)
    String phoneNumber = to.getText().toString();
    Cursor cursor =  managedQuery(intent.getData(), null, null, null, null);
    while (cursor.moveToNext())
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
       String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
          phoneNumber += ", "+name;
         phoneNumber += name;
        String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

        if ( hasPhone.equalsIgnoreCase("1"))
            hasPhone = "true";
            hasPhone = "false" ;

        if (Boolean.parseBoolean(hasPhone))

            Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
            while (phones.moveToNext())
            {   phoneNumber = phoneNumber + " <" + phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))+">";


    return phoneNumber;

What this does is when we click a "Contact" button it open a list with all the contacts, the user can select any contact and that selected contact will be added in the "To" field. I want to do the exactly same thing, but instead of displaying all the contacts i want to display only those who were recently used (call log) for selection.

Also it would be nice if you can tell how to do this with groups also.

I got this going using my own version. i used a dialog and handed it the cursor to the call log. Here is the function:

public void getCallLog() {

    String[] callLogFields = { android.provider.CallLog.Calls._ID,
            android.provider.CallLog.Calls.CACHED_NAME /* im not using the name but you can*/};
    String viaOrder = android.provider.CallLog.Calls.DATE + " DESC";
    String WHERE = android.provider.CallLog.Calls.NUMBER + " >0"; /*filter out private/unknown numbers */

    final Cursor callLog_cursor = getActivity().getContentResolver().query(
            android.provider.CallLog.Calls.CONTENT_URI, callLogFields,
            WHERE, null, viaOrder);

    AlertDialog.Builder myversionOfCallLog = new AlertDialog.Builder(

    android.content.DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int item) {

            Log.v("number", callLog_cursor.getString(callLog_cursor


    myversionOfCallLog.setCursor(callLog_cursor, listener,
    myversionOfCallLog.setTitle("Choose from Call Log");

Android - How to get a contact from call log?, Looks like Google have fixed this. I am on Pixel 3 and now I can see history of selected contact with date and call duration. ----. Step 1. Unlock your Android phone and open the Phone app from the Home screen. The Phone app may be called Dialer app in some Android phone. Step 2. Then you might see an option called " Log ", " Call Log ", " Call History ", " Recents " or " Call List ", which depends on your phone model.

You can use ContactsContract.Contacts.CONTENT_STREQUENT_URI which will give you both Frequently called and Starred contacts.

How to see complete call history of a contact?, Call History Search allows you to search by name or number in your call filter the call log for a specific contact in 4.1.2 You would have to find  For those who decided to stay with what your Android device came with, you can get your unlimited call log by using a free app called Call Log Analytics – Track Your Calls. When you first install the app, it imports the 500 call log entries your phone has. After you install the app, just let it do the work of showing you all your call logs.

From API 21 is possible to use this:

CACHED_LOOKUP_URI added in API level 21 static val CACHED_LOOKUP_URI: String The cached URI to look up the contact associated with the phone number, if it exists.

This value is typically filled in by the dialer app for the caching purpose, so it's not guaranteed to be present, and may not be current if the contact information associated with this number has changed.

How to view all calls logs for a contact?, Match contact names: Retrieve a list of contacts by matching the search string to To get the ListView object that displays the contacts, you need to call Activity. following is my code to read contact phone number from call log and i am calling the getContactID method to get contact id by passing phone number. That method must return ID of the contact which is saved in phone book.

CallLog.Calls, Learn how to download Android call history to PC, and print it out for such calls​), your device will start deleting the oldest call logs you have on your phone. call history to your computer for safekeeping, or even print off a contact's call log  Select a Contact Name to display the call history. To print your call logs straight from the app click "Print". Check your print settings, and confirm! How to Save your Android Phone Call Logs to your PC. Droid Transfer also allows you to save the call history to your computer. To do this, select the contacts whose call logs you want to save (you can ctrl-click contacts to select multiple), then click either "Copy Call Logs", "Save CSV" or "Save PDF". "Copy Call Logs" - Copies the call log

Retrieve a list of contacts, Learn how to block calls, set or cancel call forwarding, and manage caller ID and the call log on the Android version 8.0.0 Select the desired contact, then tap Done. Call logs. Select the desired call log entry, then tap Done. Call logs may approximate the amount of time you have spent on phone calls, but they do not  Viewing Android call history on computer is also available but you need to turn to some tools. Here, Android Call Logs Manager can be a good choice for you. It not only enables you to view the call logs on your phone but also allows you to manage the records or other files like contacts, messages, media files, etc. with simple clicks.

How to Download and Print your Android Call Log History, Call log manager (Edit, Add, Backup, Restore). The best and the easiest way to add and edit your phone call log. You can edit the time, date, duration, call type,  Solution: How to Get Erased Call Logs Back. Android SMS Recovery is an application with which users can bring their lost data back. It works as a deleted call log recovery app, even when you don't have a backup file. It's now available on retrieving deleted call log on Samsung, Nokia and so on from SIM card or memory card without a hitch.

  • great solution! Could you please help me know how can I display names in the dialog rather than the phone numbers?
  • just pull one of these:… from the colunIndex. im not sure which one it is , probably CACHED_NAME