CallLog.Calls.CACHED_PHOTO_URI always return empty

372 views Asked by At

I have facing very critical issue. I developing call log related apps but when i getting call log from content provider i am not able to find CallLog.Calls.CACHED_PHOTO_URI. It's always returning empty. I am using VIVO 1917( Funtouch OS_10)

 public static void loadData(Context context) {
    mainList = new ArrayList<>();
    
    String projection[] = {"_id", CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.CACHED_PHOTO_URI, CallLog.Calls.TYPE, CallLog.Calls.CACHED_NAME};
    ContentResolver contentResolver = context.getApplicationContext().getContentResolver();
    Cursor cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, projection, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);

    if (cursor == null) {
        Log.d("CALLLOG", "cursor is null");
        return;
    }

    if (cursor.getCount() == 0) {
        Log.d("CALLLOG", "cursor size is 0");
        return;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        CallLogInfo callLogInfo = new CallLogInfo();
        callLogInfo.setName(cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)));
        callLogInfo.setNumber(cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)));
        callLogInfo.setCallType(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE)));
        callLogInfo.setDate(cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)));
        callLogInfo.setDuration(cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION)));
        String ss = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_PHOTO_URI));

        Log.e("TAG", "  recent calls " + ss);
        mainList.add(callLogInfo);
        cursor.moveToNext();
    }

    
    cursor.close();
}
1

There are 1 answers

5
JensV On

Documentation from Android:

CACHED_PHOTO_URI Added in API level 23

The cached photo URI of the picture 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.

This means depending on the Dialer App which differs from manufacturers this value may not be present.

You might have a better chance by looking up the number/name in the contacts yourself and get an image this way.