1

我需要从联系人中获取联系人姓名和电话号码,并将它们放在两个列表中。使用下面的代码,我可以获得联系人姓名。但是我怎样才能得到电话号码呢?

        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());

        }
4

1 回答 1

0

使用 Xamarin.Mobile API。它处于测试阶段,但运行良好,并且是跨平台的。

http://www.xamarin.com/mobileapi

于 2013-02-19T16:14:18.190 回答