Android - 无法获取联系人照片?

标签 android image fetch contacts

我正在尝试使用联系人 ID 获取联系人图像。

这是我的代码:-

public Bitmap getDisplayPhoto(Long id)
{
    Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI,id);
    InputStream input = Contacts.openContactPhotoInputStream(this.getContentResolver(), uri);
    if (input == null)
    {
       return null;
    }
    return BitmapFactory.decodeStream(input);
}

此代码为我的所有联系人返回 null,包括那些有图像的联系人。

我做错了什么?

请帮忙!!

谢谢。

最佳答案

您的联系人是否从 Facebook 同步?因为这些似乎无法访问。

如果不是这样,您可能想试试这个:

InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(this.getContentResolver(), uri);

不确定您是否已导入 ContactsContract

关于Android - 无法获取联系人照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6201854/

相关文章:

android - ffmpeg-分割参数列表时出错 : Option not found

android - 如何用颜色填充 Canvas

python - 如何删除使用 librosa.display.specshow 创建的图中的 Y 轴标签、刻度线和轴标签

git fetch/merge 非快进更改?

PHP PDO mysql_result() 等效吗?

postgresql - PQsetSingleRowMode 低性能

android - 在没有播放服务的情况下,Google map v2 无法在 2.2 设备上使用吗?

java - 即使正确的JSON JAVA Volley,凭证响应也无效

java - 将图像旋转到 MousePos?

css - 用于旋转 slider 的图像悬停 CSS