1

I need to get the contact names and phone numbers from contacts, and put them in two lists. Using below code, I can get the contact names. But how can I get phone numbers?

        List<string> contactNames = new List<string>();
        List<string> contactNumbers = new List<string>();             

        Android.Net.Uri uri = ContactsContract.Contacts.ContentUri;

        String[] projection = new String[] {
            BaseColumnsConsts.Id,
            ContactsContract.ContactsColumnsConsts.DisplayName
        };

        String selection = string.Format("{0} = '{1}'", ContactsContract.ContactsColumnsConsts.InVisibleGroup, show_invisible ? "0" : "1");
        String[] selectionArgs = null;
        String sortOrder = string.Format("{0} COLLATE LOCALIZED ASC", ContactsContract.ContactsColumnsConsts.DisplayName);

        ICursor cursor = ManagedQuery(uri, projection, selection, selectionArgs, sortOrder);            


        if (cursor.MoveToFirst()){

            do
            {
                contactNames.Add(cursor.GetString(cursor.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.DisplayName)));                   

            } while (cursor.MoveToNext());

        }
Nalaka
  • 36
  • 3
  • You could try doing something like http://stackoverflow.com/a/12388353/1524450 once you have the contact name. – Michael Dec 09 '12 at 10:14

1 Answers1

0

Use the Xamarin.Mobile API. Its in beta, but works well, and is cross platform.

http://www.xamarin.com/mobileapi

zenith
  • 186
  • 6