@OverrIDe public VIEw newVIEw(Context context,Cursor cursor,VIEwGroup parent) { final LayoutInflater inflater = LayoutInflater.from(context); VIEw v = inflater.inflate(layout,parent,false); long contactID = Long.valueOf(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID))); String contactname = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.disPLAY_name)); boolean hasPhone = Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))); String thumbnailUri = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_thumbnail_URI)); TextVIEw name_text = (TextVIEw) v.findVIEwByID(R.ID.name_entry); if (name_text != null) { name_text.setText(contactname); } name_text.setTag(new Contact(contactID,hasPhone)); ImageVIEw thumbnail = (ImageVIEw) v.findVIEwByID(R.ID.thumbnail); if (thumbnailUri != null) { thumbnail.setimageURI(Uri.parse(thumbnailUri)); } else { thumbnail.setimageResource(R.drawable.ic_launcher); } return v; }
但是当我尝试解析存储在thumbnailUri中的Uri时,我收到以下错误:
08-09 01:58:38.619: I/System.out(1471): resolveUri Failed on bad bitmap uri: content://com.androID.contacts/contacts/1/photo
我这样做错了吗?任何帮助将不胜感激!
解决方法private Uri getPhotoUriFromID(String ID) { try { Cursor cur = getContentResolver() .query(ContactsContract.Data.CONTENT_URI,null,ContactsContract.Data.CONTACT_ID + "=" + ID + " AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'",null); if (cur != null) { if (!cur.movetoFirst()) { return null; // no photo } } else { return null; // error in cursor process } } catch (Exception e) { e.printstacktrace(); return null; } Uri person = ContentUris.withAppendedID( ContactsContract.Contacts.CONTENT_URI,Long.parseLong(ID)); return Uri.withAppendedpath(person,ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);}
这是您需要传递联系人ID的功能,您将获得可以在图像视图中轻松设置的图像的URI.
使用此功能的响应uri,如imageVIEw.setimageURI(uri)
希望它能为您的代码工作.
总结以上是内存溢出为你收集整理的如何获取Android联系人缩略图全部内容,希望文章能够帮你解决如何获取Android联系人缩略图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)