private
void readContact() {
ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.parse(
"content://com.android.contacts/raw_contacts");
Uri uri1 = Uri.parse(
"content://com.android.contacts/data");
Cursor cursor = contentResolver.query(uri,
new String[] {
"_id" },
null,
null,
null);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex(
"_id"));
Cursor cursor2 = contentResolver.query(uri1,
new String[] {
"data1",
"mimetype" },
"contact_id=?",
new String[] { id },
null);
Contacts c =
new Contacts();
while (cursor2.moveToNext()) {
String data = cursor2
.getString(cursor2.getColumnIndex(
"data1"));
String mimetype = cursor2.getString(cursor2
.getColumnIndex(
"mimetype"));
if (
"vnd.android.cursor.item/phone_v2".equals(mimetype)) {
c.setTel(data);
}
else if (
"vnd.android.cursor.item/name".equals(mimetype)) {
c.setName(data);
}
}
list.add(c);
}
转载请注明原文地址: https://ju.6miu.com/read-1126165.html