我知道可以使用以下方法获取联系人照片的uri:

Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri photoUri = Uri.withAppendedPath(person, Contacts.Photo.CONTENT_DIRECTORY);

有没有办法对rawcontact做同样的事情?
我试过了:
Uri person = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
Uri photoUri = Uri.withAppendedPath(person, Contacts.Photo.CONTENT_DIRECTORY);

但它不起作用…
我需要一个uri而不是实际的blob是因为代码在appwidget中,并且当从一个widget向启动程序传递数据时,似乎有两个meg的非常硬的限制,所以我需要使用setimageviewuri而不是setimageviewbitmap。
谢谢。

最佳答案

这是你问题的解决办法。Solution
我也遇到了同样的问题,在仔细研究和阅读了android的源代码之后,我明白了。现在(对你来说)可能已经很晚了,但不管怎样还是在这儿。

public InputStream getBitmapFromUri(String rawContactId) throws FileNotFoundException {

    final Uri photoUri = Uri.withAppendedPath(
            ContentUris.withAppendedId(RawContacts.CONTENT_URI, Long.valueOf(rawContactId)), RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
    final InputStream imageStream = contentResolver.openInputStream(photoUri);

    return imageStream;
}

08-07 13:15