2015-10-19 114 views

回答

0

這是官方文檔中檢索聯繫人圖像的方法。

public InputStream openPhoto(long contactId) { 
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY); 
Cursor cursor = getContentResolver().query(photoUri, 
     new String[] {Contacts.Photo.PHOTO}, null, null, null); 
if (cursor == null) { 
    return null; 
} 
try { 
    if (cursor.moveToFirst()) { 
     byte[] data = cursor.getBlob(0); 
     if (data != null) { 
      return new ByteArrayInputStream(data); 
     } 
    } 
} finally { 
    cursor.close(); 
} 
return null; 
} 

有此鏈接訪問link

相關問題