标签:
private void readContacts() { final String name = "vnd.android.cursor.item/name"; final String phone_v2 = "vnd.android.cursor.item/phone_v2"; ContentResolver resolver = getContentResolver(); Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); Cursor cursor = resolver.query(uri, null, null, null, null); Uri dataUri = Uri.parse("content://com.android.contacts/data"); while (cursor.moveToNext()) { String id = cursor.getString(cursor.getColumnIndex("contact_id")); if (id != null) { Cursor dataCursor = resolver.query(dataUri, null, "raw_contact_id=?", new String[]{id}, null); Contacts contacts = new Contacts(); contacts.setId(id); while (dataCursor.moveToNext()) { String data1 = dataCursor.getString(dataCursor .getColumnIndex("data1")); String mimetype = dataCursor.getString(dataCursor .getColumnIndex("mimetype")); switch (mimetype) { case name: contacts.setName(data1); break; case phone_v2: contacts.setPhone(data1); break; } } System.out.println(contacts); } } }
<uses-permission android:name="android.permission.READ_CONTACTS" />
标签:
原文地址:http://www.cnblogs.com/linson0116/p/4935589.html