我使用下面的代码,但我只需要联系人姓名,此代码从联系人、Facebook、Nimbuzz 和....中检索所有数据。Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
//numberPhone = 0;
contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,
Long.parseLong(contactId));
Uri dataUri = Uri.withAppendedPath(contactUri,
Contacts.Data.CONTENT_DIRECTORY);
try {
Cursor nameCursor = getContentResolver()
.query(dataUri,null,Data.MIMETYPE + "=?",new String[] { StructuredName.CONTENT_ITEM_TYPE }, null);
int indexDisplayName = nameCursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
nameCursor.moveToFirst();
do {
String firstName = nameCursor.getString(nameCursor
.getColumnIndex(Data.DATA2));
String lastName = nameCursor.getString(nameCursor
.getColumnIndex(Data.DATA3));
Arrayename.add(firstName+" "+lastName);
//String display = nameCursor.getString(indexDisplayName);
//Log.d("display name", "display name is: " + display);
} while (nameCursor.moveToNext());
nameCursor.close();
} catch (Exception e) {
Toast.makeText(this, "Error Happend While Reading Names",
Toast.LENGTH_SHORT).show();
}
}
如何仅获取联系人数据?