-
Notifications
You must be signed in to change notification settings - Fork 252
/
ReadContact.txt
43 lines (39 loc) · 1.46 KB
/
ReadContact.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//permissions need
<uses-permission android:name="android.permission.READ_CONTACTS" />
//code
void FillContacts()
{
var uri = ContactsContract.Contacts.ContentUri;
string[] projection = {
ContactsContract.Contacts.InterfaceConsts.Id,
ContactsContract.Contacts.InterfaceConsts.DisplayName,
ContactsContract.Contacts.InterfaceConsts.PhotoId
};
// CursorLoader introduced in Honeycomb (3.0, API11)
var loader = new CursorLoader(this, uri, projection, null, null, null);
var cursor = (ICursor)loader.LoadInBackground();
List<Contact> contactList = new List<Contact>();
if (cursor.MoveToFirst())
{
do
{
contactList.Add(
new Contact( cursor.GetLong(cursor.GetColumnIndex(projection[0])),
cursor.GetString(cursor.GetColumnIndex(projection[1])),
cursor.GetString(cursor.GetColumnIndex(projection[2]))
)
);
} while (cursor.MoveToNext());
}
}
class Contact
{ long Id;
string DisplayName;
string PhotoId;
public Contact(long Id, string DisplayName,string PhotoId)
{
this.Id = Id;
this.DisplayName = DisplayName;
this.PhotoId = PhotoId;
}
}