0

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?

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
ip696
  • 6,574
  • 12
  • 65
  • 128

1 Answers1

1

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

marmor
  • 27,641
  • 11
  • 107
  • 150
  • I know about this method and now I use it. I thought there was an opportunity get real PATH to contact photo....Just I have now 2 ways for save photo. 1 - from galary 2 - from contact(if exist). And When I pick photo from galary - I hold real path and after save I copy this photo to my app folder. But If I pick photo from contact now I hold InputStream and when save - I cope InputStream to my app folder. I have 2 methods with params String(real path) and InputStream – ip696 Jan 23 '18 at 07:09
  • there's no "real path" for contact pics, they are stored as blobs in the database itself, not on the device's filesystem – marmor Jan 23 '18 at 07:10
  • well, then I did the right thing. It just seemed like a bad approach. Thank you, your answer is in any case correct) – ip696 Jan 23 '18 at 07:12