Tuesday, 3 August 2010

Android 1.6 Reading Contacts name and phone numbers

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(People.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
NAMES = new String[cur.getCount()];
int j =0;
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(People._ID));
String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
NAMES[j] = name;
j++;
Cursor pCur = cr.query(
Contacts.Phones.CONTENT_URI,
null,
Contacts.Phones.PERSON_ID +" = ?",
new String[]{id}, null);
int i=0;
int pCount = pCur.getCount();
String[] phoneNum = new String[pCount];
String[] phoneType = new String[pCount];
while (pCur.moveToNext()) {
phoneNum[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.NUMBER));
phoneType[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.TYPE));
i++;
}
}




}

No comments:

Post a Comment