2017-02-20 3 views
0

Um Kontakt Foto uri zu bekommen, können Sie einfach brach die docs:Android bekommen RAW_CONTACT Bild uri

Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); 
return Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY); 

Aber in meinem Fall möchte ich alle RAW_CONTACTS zeigen, die Teil eines einzigen Kontakt sind, dort ich brauche ihr hochauflösendes Foto Uri. Wie kann ich einen bekommen?

Beachten Sie, dass das Miniaturbild-BLOB, das Sie in der Datentabelle unter der Contacts.Photo.PHOTO-Spalte finden können, aber das Bild hoher Auflösung nicht interessiert ist.

+0

haben Sie versucht [diesen Link] (http://stackoverflow.com/a/3509210/3800164), scheint wie nützlich für dein Problem? –

Antwort

1

Sie suchen nach ContactsContract.RawContacts.DisplayPhoto suchen,

Hier ist die offizielle Anwendungsbeispiel aus der docs (es ist für Schreiben ein Foto in ein RawContact):

public void writeDisplayPhoto(long rawContactId, byte[] photo) { 
    Uri rawContactPhotoUri = Uri.withAppendedPath(
      ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 
      RawContacts.DisplayPhoto.CONTENT_DIRECTORY); 
    try { 
     AssetFileDescriptor fd = 
      getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw"); 
     OutputStream os = fd.createOutputStream(); 
     os.write(photo); 
     os.close(); 
     fd.close(); 
    } catch (IOException e) { 
     // Handle error cases. 
    } 
} 

Hier ist, wie es zu lesen:

public byte[] readDisplayPhoto(long rawContactId) { 
    byte[] photo; 
    Uri rawContactPhotoUri = Uri.withAppendedPath(
      ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 
      RawContacts.DisplayPhoto.CONTENT_DIRECTORY); 
    try { 
     AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "r"); 
     FileInputStream is = fd.createInputStream(); 
     is.read(photo); 
     is.close(); 
     fd.close(); 
     return photo 
    } catch (IOException e) { 
     // Handle error cases. 
    } 
}