CallLog content provider returns 500 results max

穿精又带淫゛_ 提交于 2019-12-13 02:47:28

问题


For some reason, If I query the CallLog Content provider, I get maximum 500 results. Also, it seems I only get results up to 1 month ago (when my devices Phone app shows me about 8 months at the moment).

I googled it, but all I found was 'Store 'CallLog.Calls' into another table' which offers no solution.

This is my code:

String[] strFields = {
                    android.provider.CallLog.Calls.NUMBER,
                    android.provider.CallLog.Calls.DURATION,
                    android.provider.CallLog.Calls.DATE,
            };

            Cursor cursor = MainApplication.getAppContext().getContentResolver().query(
                    android.provider.CallLog.Calls.CONTENT_URI,
                    strFields,
                    null,
                    null,
                    null
            );

            if (cursor != null) {
                Log.d("aaa", cursor.getCount());
                ...
            }
            ...

I tried adding a higher limit, but nothing changed.

Does anyone know why my results are limited?

Edit:

After digging a little in Android code, I got to a method called removeExpiredEntries() in android.provider.CallLog

private static void removeExpiredEntries(Context context) {
        final ContentResolver resolver = context.getContentResolver();
        resolver.delete(CONTENT_URI, "_id IN " +
                "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER
                + " LIMIT -1 OFFSET 500)", null);
}

Which is called every time a call is added to the log :/ This means the call log content provider can return up to 500 entries.

This leaves me with the question: how does the native phone app (in my case, Samsung's phone app) shows what seems to be thousands entries more?


回答1:


So from looking at the logs, I came to the conclusion that the content provider indeed deletes entries when having more than 500, and what the device's Phone app does is save logs by it self



来源:https://stackoverflow.com/questions/19067406/calllog-content-provider-returns-500-results-max

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