Пример #1
0
        public Contact Load(string id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            CheckStatus();

            int rowId;

            if (!Int32.TryParse(id, out rowId))
            {
                throw new ArgumentException("Not a valid contact ID", "id");
            }

            ABPerson person = this.addressBook.GetPerson(rowId);

            if (person == null)
            {
                return(null);
            }

            return(ContactHelper.GetContact(person));
        }
Пример #2
0
        /// <summary>
        /// Attempts to load a contact for the specified <paramref name="id"/>.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>The <see cref="Contact"/> if found, <c>null</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> is empty.</exception>
        public Contact Load(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Trim() == String.Empty)
            {
                throw new ArgumentException("Invalid ID", "id");
            }

            Android.Net.Uri curi; string column;
            if (PreferContactAggregation)
            {
                curi   = ContactsContract.Contacts.ContentUri;
                column = ContactsContract.ContactsColumns.LookupKey;
            }
            else
            {
                curi   = ContactsContract.RawContacts.ContentUri;
                column = ContactsContract.RawContactsColumns.ContactId;
            }

            ICursor c = null;

            try
            {
                c = this.content.Query(curi, null, column + " = ?", new[] { id }, null);
                return(c.MoveToNext() ? ContactHelper.GetContact(!PreferContactAggregation, this.content, this.resources, c) : null);
            }
            finally
            {
                if (c != null)
                {
                    c.Deactivate();
                }
            }
        }