Search code examples
javaandroidsmartphone

how to force recent calls activity to show contact's name on insert


I am trying to insert a new call on my HTC programmatically.

ContentValues values = new ContentValues();
values.put(android.provider.CallLog.Calls.NUMBER, someNumber);
values.put(android.provider.CallLog.Calls.CACHED_NAME, someName);
values.put(android.provider.CallLog.Calls.CACHED_NUMBER_TYPE, 0);
values.put(android.provider.CallLog.Calls.CACHED_NUMBER_LABEL, "");
values.put(android.provider.CallLog.Calls.DATE, someTime);
values.put(android.provider.CallLog.Calls.DURATION, someDuration);
values.put(android.provider.CallLog.Calls.NEW, 1);
contentResolver.insert(uri, values);

Well, the call shows up in the list but I always see (unknown) rather than the CACHED_NAME. The same code works well on Samsung but sucks on HTC for some reason. Is it a bug like behaviour on HTC or am I missing some things here?

Any help is appreciated.


Solution

  • Alrighty. After a deep investigation I found out the reason. HTC devices for some reason are retrieving caller names from another field called "cname" rather than

    android.provider.CallLog.Calls.CACHED_NAME="name"
    

    Using the following will do the trick:

    String static final HTC_CACHED_NAME="cname"
    if (isHTCDevice) 
        values.put(HTC_CACHED_NAME, someName);
    ...
    

    Let me know!