Get the URI of rawcontact photos in Android

I know I can get the URI of a contact's photo in the following ways:

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

Is there any way to do the same thing with rawcontact?

I tried:

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

But it doesn't work

The reason why I need a URI instead of the actual blob is because the code is in the AppWidget and there seem to be some very strict restrictions on passing data from the widget to the launcher, so I need to use setimageviewuri instead of setimageviewbitmap

thank you.

resolvent:

This is the solution to your problem

I have the same problem. After mining and reading the Android source code, I got it. It may be late (for you), but it's here anyway

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;
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>