// Updates the contact information on the screen when a contact is picked. public void UpdateContactEntryFromUri(Uri uri) { ICursor cursor = Activity.ContentResolver.Query(contactUri, null, null, null, null); if (cursor != null && cursor.MoveToFirst()) { int idx = cursor.GetColumnIndex(ContactsContract.ContactsColumns.DisplayName); string name = cursor.GetString(idx); idx = cursor.GetColumnIndex(ContactsContract.ContactsColumns.PhotoId); string hasPhoto = cursor.GetString(idx); Uri photoUri = Uri.WithAppendedPath(contactUri, ContactsContract.Contacts.Photo.ContentDirectory); ImageView contactPhoto = (ImageView)Activity.FindViewById(Resource.Id.contact_photo); if (hasPhoto != null) { contactPhoto.SetImageURI(photoUri); } else { Drawable defaultContactDrawable = Activity.Resources.GetDrawable(Resource.Drawable.ic_contact_picture); contactPhoto.SetImageDrawable(defaultContactDrawable); } TextView contactName = (TextView)Activity.FindViewById(Resource.Id.contact_name); contactName.SetText(name, TextView.BufferType.Normal); Activity.FindViewById(Resource.Id.contact_entry).Visibility = ViewStates.Visible; Activity.FindViewById(Resource.Id.attach_person).Visibility = ViewStates.Gone; Activity.FindViewById(Resource.Id.click_to_change).Click += delegate { FindContact(); }; Log.Info(Tag, string.Format("Contact updated. Name {0}, PhotoUri {1}", name, photoUri)); } }
public Bitmap LoadBitmapFromContactUri(Uri contactUri) { if (contactUri == null) { return(null); } Bitmap result = null; ICursor cursor = Activity.ContentResolver.Query(contactUri, null, null, null, null); if (cursor != null && cursor.MoveToFirst()) { int idx = cursor.GetColumnIndex(ContactsContract.ContactsColumns.PhotoId); string hasPhoto = cursor.GetString(idx); Uri photoUri = Uri.WithAppendedPath(contactUri, ContactsContract.Contacts.Photo.ContentDirectory); if (hasPhoto != null) { try { result = MediaStore.Images.Media.GetBitmap(Activity.ContentResolver, photoUri); } catch (IOException e) { Log.Error(TAG, string.Format("Failed to load resource. Uri {0}", photoUri), e); } } else { Drawable defaultContactDrawable = Activity.Resources.GetDrawable(Resource.Drawable.ic_contact_picture); result = ((BitmapDrawable)defaultContactDrawable).Bitmap; } } return(result); }