protected override void OnActivityResult (int requestCode, Result resultCode, Intent data) { if (requestCode == ligacao_agenda && resultCode == Result.Ok) { if (data == null || data.Data == null) return; var addressBook = new AddressBook (this); addressBook.PreferContactAggregation = true; var pathSegments = data.Data.PathSegments; var contact = addressBook.Load (pathSegments[pathSegments.Count - 1]); if (contact == null) contact = addressBook.Load (pathSegments[pathSegments.Count - 2]); if (contact == null) return; var mobile = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Mobile select p.Number).FirstOrDefault (); if (string.IsNullOrEmpty (mobile)) return; var uri = Android.Net.Uri.Parse (string.Format ("tel:{0}", mobile)); var intent = new Intent (Intent.ActionView, uri); StartActivity (intent); } }
//Get Photo and Name from Contact protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (requestCode != 101 || resultCode != Result.Ok) return; if (data == null || data.Data == null) return; var addressBook = new AddressBook(Application.Context) { PreferContactAggregation = false }; var contact = addressBook.Load(data.Data.LastPathSegment); if (string.IsNullOrEmpty(contact.DisplayName)) { Toast.MakeText(this, Resources.GetString(Resource.String.NoNameString), ToastLength.Short).Show(); return; } _editText.Text = contact.DisplayName; PlayerImage = contact.GetThumbnail(); }
public void LoadBitmap(int desiredSize) { try { if (Image != null) { Image.Recycle(); Image.Dispose(); } if (string.IsNullOrEmpty(PhotoPath)) { SetDefaultImage(); } else if (FromContacts) { var addressBook = new AddressBook(Application.Context) { PreferContactAggregation = false }; var contact = addressBook.Load(PhotoPath); var image = contact.GetThumbnail(); Image = image == null ? GetDefaultImage() : image.GetRoundedCornerBitmap(); } else { var image = BitmapExtensions.DecodeBitmap(PhotoPath, desiredSize, desiredSize); Image = image == null ? GetDefaultImage() : image.GetRoundedCornerBitmap(); } } catch (Exception ex) { GaService.TrackAppException("Player", "LoadBitmap", ex, false); SetDefaultImage(); if (!string.IsNullOrEmpty(PhotoPath)) PhotoPath = null; } }
private static void AddContactInfo(ABPerson selectedPerson, Item item) { // find the contact in the address book var book = new AddressBook(); Contact contact = null; if (book.LoadSupported) contact = book.Load(selectedPerson.Id.ToString()); else contact = book.FirstOrDefault(c => c.Id == selectedPerson.Id.ToString()); if (contact == null) return; // make a copy of the item var itemCopy = new Item(item, true); // get more info from the address book var mobile = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Mobile select p.Number).FirstOrDefault(); var home = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Home select p.Number).FirstOrDefault(); var work = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Work select p.Number).FirstOrDefault(); var email = (from em in contact.Emails select em.Address).FirstOrDefault(); //var website = (from w in contact.Websites // select w.Address).FirstOrDefault(); string birthday = null; if (selectedPerson.Birthday != null) birthday = ((DateTime)selectedPerson.Birthday).ToString("d"); if (birthday != null) item.GetFieldValue(FieldNames.Birthday, true).Value = birthday; if (mobile != null) item.GetFieldValue(FieldNames.Phone, true).Value = mobile; if (home != null) item.GetFieldValue(FieldNames.HomePhone, true).Value = home; if (work != null) item.GetFieldValue(FieldNames.WorkPhone, true).Value = work; if (email != null) item.GetFieldValue(FieldNames.Email, true).Value = email; /* if (website != null) item.GetFieldValue(FieldNames.Website, true).Value = website */ // save changes to local storage Folder folder = App.ViewModel.LoadFolder(item.FolderID); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List<Item>() { itemCopy, item }, BodyTypeName = "Item", ID = item.ID }); // add the zaplify contact header to a special Zaplify "related name" field // use the native address book because the cross-platform AddressBook class is read-only var ab = new ABAddressBook(); var contactToModify = ab.GetPerson(selectedPerson.Id); /* RelatedNames doesn't work on a real device (iPad) var relatedNames = contactToModify.GetRelatedNames().ToMutableMultiValue(); if (relatedNames.Any(name => name.Label == ZaplifyContactHeader)) { // remove the existing one (can't figure out a way to get a mutable ABMultiValueEntry out of zapField) var zapField = relatedNames.Single(name => name.Label == ZaplifyContactHeader); relatedNames.RemoveAt(relatedNames.GetIndexForIdentifier(zapField.Identifier)); } // add the Zaplify related name field with the itemID value relatedNames.Add(item.ID.ToString(), new MonoTouch.Foundation.NSString(ZaplifyContactHeader)); contactToModify.SetRelatedNames(relatedNames); */ var zapField = contactToModify.Note; if (zapField == null) contactToModify.Note = ZaplifyContactHeader + item.ID.ToString(); else { if (zapField.Contains(ZaplifyContactHeader)) { var idstring = GetContactID(zapField); if (idstring != null) contactToModify.Note = zapField.Replace(idstring, item.ID.ToString()); else contactToModify.Note += String.Format("\n{0}{1}", ZaplifyContactHeader, item.ID.ToString()); } else contactToModify.Note += String.Format("\n{0}{1}", ZaplifyContactHeader, item.ID.ToString()); } // save changes to the address book ab.Save(); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // // Get the contact ID that is passed in // from the main activity // String contactID = String.Empty; if(bundle != null) { contactID = bundle.GetString("contactID"); } else { contactID = Intent.GetStringExtra("contactID"); } // // Get the address book // var book = new AddressBook (this); // // Important: PreferContactAggregation must be set to the // the same value as when the ID was generated (from the // previous activity) // book.PreferContactAggregation = true; Contact contact = book.Load (contactID); // // If the contact is empty, we'll // display a 'not found' error // String displayName = "Contact Not Found"; String mobilePhone = String.Empty; // // Set the displayName variable to the contact's // DisplayName property // if(contact != null) { displayName = contact.DisplayName; var phone = contact.Phones.FirstOrDefault (p => p.Type == PhoneType.Mobile); if(phone != null) { mobilePhone = phone.Number; } } // // Show the contacts display name and mobile phone // SetContentView (Resource.Layout.contact_view); var fullNameTextView = FindViewById<TextView> (Resource.Id.full_name); fullNameTextView.Text = displayName; var mobilePhoneTextView = FindViewById<TextView> (Resource.Id.mobile_phone); mobilePhoneTextView.Text = mobilePhone; }
//Get Photo and Name from Contact protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { if (resultCode == Result.Canceled) return; if (requestCode == 2) { _player.FromContacts = false; data.GetMediaFileExtraAsync(this).ContinueWith(t => PlayerImagePath = t.Result.Path); } if (requestCode == 3) { if (data == null || data.Data == null) return; var addressBook = new AddressBook(Application.Context) { PreferContactAggregation = false }; var contact = addressBook.Load(data.Data.LastPathSegment); if (string.IsNullOrEmpty(contact.DisplayName)) Toast.MakeText(this, Resources.GetString(Resource.String.NoNameString), ToastLength.Short) .Show(); else _editText.Text = contact.DisplayName; if (contact.GetThumbnail() != null) { _player.FromContacts = true; PlayerImagePath = data.Data.LastPathSegment; } else { _player.FromContacts = false; PlayerImagePath = null; } } } catch (Exception exception) { GaService.TrackAppException(this.Class, "OnActivityResult", exception, false); } }