通过 LOOKUP_KEY 和 openContactPhotoInputStream 便捷方法加载联系人图片
我正在修改我的应用程序,以便按照 API 文档的建议使用 LOOKUP_KEY 而不是 _ID 来存储联系人信息。我遇到的唯一问题是我无法再加载联系人的照片。
有问题的代码是这样的:
InputStream s = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), contactUri);
这返回以下错误: java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/lookup/1424i118.2312i1220228108/photo
contactUri我用作参数的参数是通过以下方式获取的: Uri contactUri = Uri.withAppishedPath(Contacts.CONTENT_LOOKUP_URI, contact_key);
在此示例中,contact_key
为 1424i118.2312i1220228108
根据 API 文档,此帮助程序方法应该有效与 CONTENT_URI
或CONTENT_LOOKUP_URI
,我正在使用。
有什么想法吗?谢谢。
I'm modifying my app to store information on contacts using LOOKUP_KEY instead of _ID as suggested by the API docs. The only problem I'm having is that I'm no longer able to load the contact's photo.
The problematic code is this one:
InputStream s = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), contactUri);
This is returning the following error: java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/lookup/1424i118.2312i1220228108/photo
The contactUri that I am using as argument is acquired by the following: Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, contact_key);
and in this example, contact_key
is 1424i118.2312i1220228108
Based on the API docs, this helper method should work with both CONTENT_URI
or CONTENT_LOOKUP_URI
, which I am using.
Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何有类似问题的人来说,这对我来说很有效:
For anyone with a similar problem, this did the trick for me: