Exemplo n.º 1
0
        public string GetContactNameFromNumber(string phoneNumber)
        {
            var contactName = phoneNumber;

            for (int x = 0; x < this.PhoneList.Count; x++)
            {
                var possibleContactPhone         = this.PhoneList.ElementAt(x);
                var possibleContactCleansedPhone = PhoneHelper.GetCleansedPhoneNumber(possibleContactPhone.Number);
                var cleansedTextMessageNumber    = PhoneHelper.GetCleansedPhoneNumber(phoneNumber);

                if (possibleContactCleansedPhone == cleansedTextMessageNumber && possibleContactCleansedPhone.Length > 0)
                {
                    var contactId = possibleContactPhone.ContactID;

                    for (int y = 0; y < this.ContactList.Count; y++)
                    {
                        var possibleContact = this.ContactList.ElementAt(y);

                        if (possibleContact.ID == contactId)
                        {
                            contactName = possibleContact.DisplayName;
                        }
                    }
                }
            }

            return(contactName);
        }
Exemplo n.º 2
0
        public static Contact GetContactFromAddress(ContentResolver cr, string address)
        {
            string contactId;
            string contactName;
            string stringUri;
            string dbPhone;

            Android.Net.Uri picUri         = null;
            string          formattedPhone = PhoneHelper.GetCleansedPhoneNumber(address);
            Contact         contact        = new Contact();

            contact.Number      = address;
            contact.DisplayName = address;

            var phoneCursor = cr.Query(
                ContactsContract.CommonDataKinds.Phone.ContentUri,
                new string[] { "data1", "contact_id", "display_name", "photo_uri", "data1" },
                "REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(data1, ' ', ''), '+', ''), '(',''), ')',''), '-', '') LIKE '%" + formattedPhone + "'",
                //"data1 LIKE '%8480'",
                null, null);

            if (phoneCursor.MoveToFirst())
            {
                dbPhone     = phoneCursor.GetString(phoneCursor.GetColumnIndex("data1"));
                contactId   = phoneCursor.GetString(phoneCursor.GetColumnIndex("contact_id"));
                contactName = phoneCursor.GetString(phoneCursor.GetColumnIndex("display_name"));
                stringUri   = phoneCursor.GetString(phoneCursor.GetColumnIndex("photo_uri"));

                if (PhoneHelper.GetCleansedPhoneNumber(dbPhone) == formattedPhone)
                {
                    if (stringUri != null)
                    {
                        picUri = Android.Net.Uri.Parse(stringUri);
                    }

                    contact.ID          = contactId;
                    contact.DisplayName = contactName;
                    contact.PictureUri  = picUri;
                }
            }

            return(contact);
        }