2012-07-19 54 views
0

我正在设置SD卡中的联系人图像,通过我的应用程序,我试图将它放在列表适配器中。我能够正确地获取图像。但是,当我试图设置在setImageURI()中找不到文件异常;

img.setImageURI(uri); 

有时我得到找不到文件exception.Even问题与URI变换成bitmap.I具有与形象,2接触四个触点能否正常显示,剩下的两我得到文件没有发现exception.please帮助。

+0

尝试使用img.setImageURI(Uri.Parse( “sdcard_image_path”)); – NullPointerException 2012-07-19 08:57:03

回答

0

请参阅此链接 https://stackoverflow.com/a/4240238/1441666

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); 
} 
+0

嘿。我得到像“content:content://com.android.contacts/contacts/7/photo”这样的联系人图片。它告诉这个文件没有发现异常 – 2012-07-19 09:28:41

+0

看到我编辑了我的答案 – Nirali 2012-07-19 09:45:10

+0

你可以分享正确的代码来获取联系人ID吗? – 2012-07-20 04:51:11