CallLog.Calls.CACHED_LOOKUP_URI 不适用于小米/MIUI 设备
我需要获取给定呼叫日志的联系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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论