public async Task <IEnumerable <UserContact> > GetAllContacts() { if (_contacts != null) { return(_contacts); } var contacts = new List <UserContact>(); await _book.RequestPermission().ContinueWith(t => { if (!t.Result) { Console.WriteLine("Sorry ! Permission was denied by user or manifest !"); return; } foreach (var contact in _book.ToList().Where(c => c.Phones.Any())) // Filtering the Contact's that has at least one number { var firstOrDefault = contact.Phones.FirstOrDefault(); if (firstOrDefault != null) { contacts.Add(new UserContact { ContactFirstName = contact.FirstName, ContactLastName = contact.LastName, ContactDisplayName = contact.DisplayName, ContactPhone = firstOrDefault.Number, }); } } }); _contacts = (from c in contacts orderby c.ContactFirstName select c).ToList(); return(_contacts); }
public async Task <IEnumerable <MobileUserContact> > GetAllContacts() { if (_contacts != null) { return(_contacts); } var contacts = new List <MobileUserContact>(); await _book.RequestPermission().ContinueWith(t => { if (!t.Result) { Console.WriteLine("Sorry ! Permission was denied by user or manifest !"); return; } foreach (var contact in _book.ToList()) { var firstOrDefault = contact.Emails.FirstOrDefault(); contacts.Add(new MobileUserContact() { Contact_FirstName = contact.FirstName + "===>" + contact.LastName + "===>" + contact.DisplayName, Contact_LastName = contact.LastName, Contact_DisplayName = contact.DisplayName, Contact_EmailId = firstOrDefault != null ? firstOrDefault.Address : String.Empty }); } }); _contacts = (from c in contacts orderby c.Contact_FirstName select c).ToList(); return(_contacts); }
public async Task <IEnumerable <Contacter> > GetContactors() { var book = new Xamarin.Contacts.AddressBook(); var datas = new List <Contacter>(); await book.RequestPermission().ContinueWith(t => { if (t.Result) { //foreach (Contact contact in book.OrderBy(c => c.LastName)) { var cs = book.ToList() .OrderBy(c => c.DisplayName); foreach (var c in cs) { foreach (var p in c.Phones) { datas.Add(new Contacter() { Phone = p.Number, PhoneType = p.Label, Name = c.DisplayName, Img = this.GetBytes(c.GetThumbnail()) }); } } } }); return(datas); }
public async Task <List <MobileUserContact> > GetAllContact() { var contacts = new List <MobileUserContact>(); await _book.RequestPermission().ContinueWith(t => { if (!t.Result) { Console.WriteLine("Sorry ! Permission was denied by user or manifest !"); return; } foreach (var contact in _book.ToList()) { var phone = contact.Phones.FirstOrDefault(); var email = contact.Emails.FirstOrDefault(); var image = contact.GetThumbnail(); var myMobileUserContact = new MobileUserContact(); if (image != null) { MemoryStream stream = new MemoryStream(); image.Compress(Bitmap.CompressFormat.Png, 0, stream); byte[] imageData = stream.ToArray(); myMobileUserContact.imagesource = ImageSource.FromStream(() => new MemoryStream(imageData)); myMobileUserContact.ImageCheck = false; } else { myMobileUserContact.imagesource = "avatar.png"; myMobileUserContact.ImageCheck = true; } myMobileUserContact.DisplayName = contact.DisplayName; myMobileUserContact.PhoneNumber = phone != null ? phone.Number : string.Empty; myMobileUserContact.Email = email != null ? email.Address : string.Empty; _contacts.Add(myMobileUserContact); //_contacts.Add(new MobileUserContact() //{ // DisplayName = contact.DisplayName, // PhoneNumber = phone!=null ? phone.Number : string.Empty, // Email = email!=null ? email.Address : string.Empty, //}); } }); //contacts = (from c in contacts orderby c.DisplayName select c).ToList(); return(_contacts); }