簡體   English   中英

如果您有電話號碼,Android會獲取聯系人照片顯示圖片

[英]Android get contact photo display picture if you have phone number

我擁有所有聯系人日志,我想將聯系人圖像附加到電話號碼中,如果沒有聯系人圖像,則不知道該圖像。

我該怎么做? 我嘗試了很多方法,但沒有任何幫助。

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

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

訪問此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM