1 year ago

#383066

test-img

6uzm4n

CallLog.Calls.CACHED_LOOKUP_URI not working on Xiaomi/MIUI devices

I need to get the contact URI given the Call Log in order to be able to open the native "Contacts" app to show the info of the Contact that made a call, if any. In order to do this, CallLog.Calls have the property CACHED_LOOKUP_URI so you can access the contact that made the call. However, this is not working on Xiaomi devices.

This is a simplified version of the code I'm using:

Uri queryUri = CallLog.Calls.CONTENT_URI;

String[] projection = new String[]{
        CallLog.Calls._ID,
        CallLog.Calls.CACHED_NAME,
        CallLog.Calls.CACHED_LOOKUP_URI,
};

String sortOrder = CallLog.Calls.DATE + " DESC";

Cursor cursor = context.getContentResolver().query(queryUri, projection, null, null, sortOrder);

int nameIndex = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int uriIndex = cursor.getColumnIndex(CallLog.Calls.CACHED_LOOKUP_URI);


while (cursor.moveToNext()) {
    String callerName = cursor.getString(nameIndex); // -> Contact name String on every device I tested this on
    String uri = cursor.getString(uriIndex); // -> null on Xiaomi devices, correct URI String on every other device
}

As stated, this seems to only happen on Xiaomi devices. I know there are workaraunds by getting the number and doing another query in the Contacts database, but this is cumbersome at best, even more so when there is a native property that would allow me to do this by default.

java

android

contacts

calllog

xiaomi

0 Answers

Your Answer

Accepted video resources