0
계정 유형의 연락처를 제외한 모든 전화의 연락처를 나열하는 연락처 선택기를 만들어야합니다.계정 유형의 그룹을 제외한 연락처 연락처
public String[] getGroupIds(Context context, String group){
final Cursor groupCursor = context.getContentResolver().query(
GroupWrap.CONTENT_URI,
GroupWrap.PROJECTION,
GroupWrap.SELECTION_GROUP_ID,
new String[]{group},
null);
String[] ids = new String[groupCursor.getCount()];
int i = 0;
final int contactNumberColumnType = groupCursor.getColumnIndex(GroupWrap.COLUMN_TYPE);
final int contactNumberColumnIndex = groupCursor.getColumnIndex(GroupWrap.COLUMN_ID);
while (groupCursor.moveToNext()) {
ids[i++] = Integer.toString(groupCursor.getInt(contactNumberColumnIndex));
Log.v(TAG, " account type : " + groupCursor.getString(contactNumberColumnType)
+ " : ids[]" + groupCursor.getInt(contactNumberColumnIndex));
}
return ids;
}
final private static class GroupWrap {
private GroupWrap() {
}
public static final String[] PROJECTION =
new String[] {Groups.ACCOUNT_TYPE, Groups._ID};
public static final String COLUMN_TYPE = Groups.ACCOUNT_TYPE;
public static final String COLUMN_ID = Groups._ID;
public static final Uri CONTENT_URI = Groups.CONTENT_URI;
public static final String SELECTION_OTHER_GROUP_ID = GroupWrap.COLUMN_TYPE + "!=?";
public static final String SELECTION_GROUP_ID = GroupWrap.COLUMN_TYPE + "=?";
}
: 모든 그룹 ID 계정 유형이 내가 쿼리 그룹 = "com.account.myaccount"
첫째 : 나는 목록에서 제거하려는 계정 유형이 예 : 나는이 길을 따라했다
그리고 나는 그룹을 제외한 모든 연락처 조회 :
public Cursor getContactGroupIDs(String[] groupIds, Context context){
String selection = ContactsQuery.COLUMN_NAME + " NOTNULL) AND ("
+ ContactsQuery.COLUMN_NAME + " !='') AND ";
StringBuffer buffer = new StringBuffer(selection);
for(int i = 0; i < groupIds.length; i++){
buffer.append(" (" + GroupMembership.GROUP_ROW_ID + " !=?) AND ");
}
// remove ") AND "
if(buffer.length() > 0){
buffer.delete(buffer.length() - 6, buffer.length());
}
selection = buffer.toString();
Log.v(TAG, "selection : " + selection);
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cursor = context.getContentResolver().query(ContactsQuery.CONTENT_URI,
ContactsQuery.PROJECTION, selection, groupIds, sortOrder);
return cursor;
}
final public static class ContactsQuery {
private ContactsQuery() {
}
public static final String COLUMN_NAME = Data.DISPLAY_NAME;
public static final String COLUMN_ID = Data._ID;
public static final String COLUMN_CONTACT_ID = Data.CONTACT_ID;
public static final Uri CONTENT_URI = Data.CONTENT_URI;
public static final String[] PROJECTION =
new String[] {COLUMN_NAME, COLUMN_CONTACT_ID};
}
을 그리고 모든 combinate :
public List<PickerContactRow> getContactExceptGroup(Context context, String group){
String[] groupIds = getGroupIdsExcept(context, group);
List<PickerContactRow> result = new ArrayList<PickerContactRow>();
Set<Long> seen = new HashSet<Long>();
Cursor cursor = this.getContactGroupIDs(groupIds, context);
int indexOfContactId = cursor.getColumnIndex(ContactsQuery.COLUMN_CONTACT_ID);
int indexOfName = cursor.getColumnIndex(ContactsQuery.COLUMN_NAME);
while (cursor.moveToNext()) {
long contactID = cursor.getLong(indexOfContactId);
if (!seen.contains(contactID)) {// remove duplicate contact
seen.add(contactID);
PickerContactRow contactRow = new PickerContactRow();
contactRow.setId(contactID);
contactRow.setName(cursor.getString(indexOfName));
Log.v(TAG, "row : " + contactRow);
//+ "group : " + cursor.getString(columnGroup));
result.add(contactRow);
}
}
return result;
}
을
이상한 계정 이름이 표시되는 문제가 있습니다. 계정 이름 대신 일부 이메일. 내 이미지 참조 :
날 문제를 해결 도와주세요. 또는 다른 방법으로 계정을 필터링 할 수 있습니까? CursorAdapter를 사용할 수있는 솔루션을 찾고 있습니다. 내 접근 방식으로 CursorAdapter를 사용할 수 없습니다.