在 Android 中获取联系人照片的最佳(最有效)方法
我正在从联系人中提取信息,并希望显示关联的照片(如果有的话)。似乎有几种方法可以做到这一点:
获取用户的 ID,然后:
Uri uri = ContentUris.withAppishedId(ContactsContract.Contacts.CONTENT_URI, id);
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);您可以检索用户的 PHOTO_ID。我还没有深入研究确切的步骤,但想必有一种方法可以使用 PHOTO_ID 来获取照片。
还有一个 PHOTO_URI,我再次假设有一种方法可以使用它来获取照片。
现在,我的代码使用的是方法1,并且运行得很好。我想知道的是:方法 2 或 3(或我没有读过的方法)更快/更有效吗?我自然希望让我的应用程序尽可能快。任何建议将不胜感激。
I am pulling information from the contacts, and want to display the associated photo (if there is one). There seem to be several ways to do it:
Get the user's ID, and then:
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);You can retrieve the user's PHOTO_ID. I haven't dug into the exact steps, but presumably, there's a way to use the PHOTO_ID to get the photo.
There's also a PHOTO_URI, and again, I assume there's a way to use that to get the photo.
Right now, my code is using the method 1, and it's working just fine. What I'm wondering is this: Is method 2 or 3 (or one I haven't read about) faster/more efficient? I naturally want to make my app as fast as possible. Any advice would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ContactsContract.Contacts.Photo
的文档包含一些示例代码,但我猜测是,这几乎就是openContactPhotoInputStream
正在为您做的事情。The documentation for
ContactsContract.Contacts.Photo
contains some sample code, but my guess is that it's pretty much whatopenContactPhotoInputStream
is doing for you.