CallLog.Calls.CACHED_LOOKUP_URI 不适用于小米/MIUI 设备

发布于 2025-01-19 10:33:47 字数 1011 浏览 0 评论 0原文

我需要获取给定呼叫日志的联系URI,以便能够打开本机“联系人”应用程序,以显示拨打电话的联系信息(如果有)。为此,calllog.calls具有属性cached_lookup_uri,因此您可以访问调用的联系人。但是,这不适用于小米设备。

这是我正在使用的代码的简化版本:

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
}

如前所述,这似乎仅在小米设备上发生。我知道通过获得数字并在联系人数据库中进行另一个查询来有一些工作,但这充其量很麻烦,甚至在有一个本机属性允许我默认情况下进行此操作时,更是如此。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文