How to force refresh on CallLog.Calls.CACHED_NAME column?

余生颓废 提交于 2019-12-24 01:07:25

问题


My goal is to collect all unknown phone numbers from the Call Log. This can be achieved by the following code:

private static final String[] CALLOG_PROJECTION = {CallLog.Calls._ID,
        CallLog.Calls.CACHED_NAME, CallLog.Calls.NUMBER};
private static final String CALLOG_WHERE = CallLog.Calls.CACHED_NAME + " is null";

Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, CALLOG_PROJECTION,
        CALLOG_WHERE, null, CallLog.Calls.DATE + " DESC");

This works well, but after i've created a contact from an unknown number, the result of the query still contains the unknown number.

If i open the Call Log activity window, i can see as the number changes to the name of the contact within a few seconds. So, the activity refreshes the CACHED_NAME column.

My question is, how can i programatically refresh (actualize) the Call Log ?


回答1:


I landed on this question looking for ways to optimize what you're trying to do. Instead of using cached_name, I queried the Phone content provider for every number to get the actual name, but this led to performance issues.

I noticed that the stock application refreshes the list when a change occurred, as you did.

I'm going to implement a ContentObserver on the Phones table and update my name when that happens, I'll post if it works.


EDIT

I was checking the (Google's) Contacts app source code and they basically show the list with the CACHED_NAME first and, after the list is displayed, they check (on the background) if there were any changes to the contacts details. If there were any, they update the CallLog record and the list.

Basically, I've implemented something similar and it works. There were some performance issues when you scrolled the list while it was checking on the background for changes, because in a CallLog there are a lot of repeated numbers. So basically you just have to verify if those numbers are already being checked out.

Hope it helps!



来源:https://stackoverflow.com/questions/3828930/how-to-force-refresh-on-calllog-calls-cached-name-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!