読者です 読者をやめる 読者になる 読者になる

連絡先のグループ検索

ただしこの方法だと、グループに所属している連絡先しか取得できないので
ContactsContract.Dataではなく、ContactsContract.Contactsを使用して
全ての連絡先を取得+グループを取得することが可能。

// 名前一覧検索
Cursor curName = resolver.query(
		ContactsContract.Data.CONTENT_URI,
		new String[] { 
				ContactsContract.Contacts._ID,
				StructuredName.CONTACT_ID, 
				StructuredName.PHONETIC_FAMILY_NAME, 
				StructuredName.PHONETIC_MIDDLE_NAME, 
				StructuredName.PHONETIC_GIVEN_NAME 
		},
		ContactsContract.Data.MIMETYPE + "=?",
		new String[] { 
				StructuredName.CONTENT_ITEM_TYPE 
		},
		StructuredName.CONTACT_ID + " ASC"
);
// グループメンバー検索
Cursor curGrp = resolver.query(
		ContactsContract.Data.CONTENT_URI,
		 new String[] {
				GroupMembership.CONTACT_ID,
				GroupMembership.DISPLAY_NAME,
				GroupMembership.GROUP_ROW_ID
		},
		ContactsContract.Contacts.Data.MIMETYPE + "=?",
		new String[] { 
				GroupMembership.CONTENT_ITEM_TYPE 
		},//
		null
);
// Join
CursorJoiner joiner = new CursorJoiner(curName, new String[]{ StructuredName.CONTACT_ID }, curGrp, new String[]{ GroupMembership.CONTACT_ID });
for (CursorJoiner.Result joinerResult : joiner) {
	try{
		if (joinerResult == Result.RIGHT) {
			String id =  curName.getString(curName.getColumnIndex(ContactsContract.Contacts._ID));
			String id2 =  curName.getString(curName.getColumnIndex(StructuredName.CONTACT_ID));
			String id3 =  curGrp.getString(curGrp.getColumnIndex(GroupMembership.CONTACT_ID));
			String displayName = curGrp.getString(curGrp.getColumnIndex(GroupMembership.DISPLAY_NAME));
			String groupId =  curGrp.getString(curGrp.getColumnIndex(GroupMembership.GROUP_ROW_ID));
			String family = curName.getString(curName.getColumnIndex(StructuredName.PHONETIC_FAMILY_NAME));
			String middle = curName.getString(curName.getColumnIndex(StructuredName.PHONETIC_MIDDLE_NAME));
			String given = curName.getString(curName.getColumnIndex(StructuredName.PHONETIC_GIVEN_NAME));
			String kana_name = "";
			//memberList.add(new Name(displayName, phoneticName));
			
			AddressBookUserInfo addressinfo = new  AddressBookUserInfo();
			addressinfo.setId(id);
			addressinfo.setDispName(displayName);
			addressinfo.setGroupId(groupId);

			if(family!=null) kana_name = family;
			if(middle!=null) {
				 if(kana_name.length()!=0) {
					kana_name = kana_name+" " + middle;
				 } else {
					kana_name = kana_name+middle;
				 }
			 }
			 if(given!=null) {
				 if(given.length()!=0) {
					kana_name = kana_name+" " + given;
				 } else {
					kana_name = kana_name+given;
				 }
			 }
			addressinfo.setKanaName(kana_name);
			
			list.add(addressinfo);
		}
		
	} catch(Exception e) {

	}

}

参考:
http://engineer-brain.blogspot.com/2010/07/android-cursorjoiner.html
http://d.hatena.ne.jp/thorikawa/20101006/p1
http://www.saturn.dti.ne.jp/~npaka/android/LiveFolderEx/index.html