ip696
ip696

Reputation: 7094

Copy contact photo to my folder

I get contact photo URI

Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.valueOf(contactID));

And I can now show this photo with Picaso:

Picasso.with(mainUserPhoto.getContext())
                    .load(uri)
                    .placeholder(R.drawable.image_placeholder)
                    .error(R.drawable.folder_placeholder)
                    .into(mainUserPhoto);

It is worked. But I need copy this image to my folder too. How can I copy this contact photo to my Folder?

Upvotes: 0

Views: 102

Answers (1)

marmor
marmor

Reputation: 28199

In the ContactsContract.Contacts docs there's a convenience method called openContactPhotoInputStream

So you can do:

Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.valueOf(contactId));
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), contactUri, true);

Se save an InputStream to a local file, see this: https://stackoverflow.com/a/10857407/819355

Upvotes: 1

Related Questions