2012-05-26 94 views
0

我想要將未隱藏的聯繫人圖片照片設置爲Android 2.0以上的全屏圖像背景。我用下面的代碼來獲得裁剪縮略圖但照片是全屏幕的畫廊,我如何才能獲得這張照片未隱藏的聯繫人照片

該代碼給出了裁剪的縮略圖,如何獲取uncropped的全屏

 public static Bitmap loadContactPhoto(ContentResolver cr, long id) { 
     Uri uri =    ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); 
     InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); 
     if (input == null) { 
      return null; 
     } 
     return BitmapFactory.decodeStream(input); 
    } 

回答

1

Android文檔說

只讀包含 聯繫人的主照片單個聯繫人的子目錄。該照片可以以最多兩種方式存儲 - 默認的「照片」是直接存儲在 數據行中的縮略圖大小的圖像,而「顯示照片」,(如果存在的話),是較大的 版本存儲爲一份文件。

從文檔

再次

public InputStream openDisplayPhoto(long contactId) { 
    Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 
    Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO); 
    try { 
     AssetFileDescriptor fd = 
      getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r"); 
     return fd.createInputStream(); 
    } catch (IOException e) { 
     return null; 
    } 
} 
+0

聯繫人已被棄用需要使用ContactsContract API V5及以上則不能看到一種方式來獲得高分辨率的圖像,直到它有一些API API 14輕鬆搞定但如何運行Android 2.0-2.3的手機 – tech74

+0

如果你找不到任何東西,我建議你使用它,你可以升級你的應用程序與一個新的版本,當最後刪除聯繫人。關於'棄用'的討論http://stackoverflow.com/questions/10297293/andorid-how-can-i-replace-the-deprecated-tabhost可能是有用的。 –

+0

道歉DISPLAY_PHOTO字段你以上只有API 14及以上,所以看起來像V4.0之前,只有縮略圖 – tech74