2014-06-18 3 views
0

현재 내 응용 프로그램에서 followign Cursor 쿼리로 모든 연락처를 가져옵니다."일반"연락처 만 가져 오기

String[] columnsToReturn = new String[] { 
    ContactsContract.Contacts._ID, 
    ContactsContract.Contacts.DISPLAY_NAME_PRIMARY 
}; 

Cursor contactsCursor = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, columnsToReturn, null, null, null); 

이렇게하면 Skype, WhatsApp 등 모든 연락처가 반환됩니다.이 기능은 필요하지 않습니다. 나는 단지 "정상적인"것만 원한다. 앱용이 아닌 Google 계정에 저장된 앱. 어떻게해야합니까?

또한 사용자 항목을 제외 할 수 있습니까? 예를 들어, 내 이름은 여러 다른 모든 전자 메일 주소의 목록에 여러 번 나타납니다.

답변

0

ContactsContract.Contacts 테이블에 "통합 된"연락처가 있습니다.

... 동일한 사람을 나타내는 원시 연락처 집합에 대한 레코드입니다.

특정 계정 또는 계정 유형의 연락처를 쿼리하려면 RawContacts을 사용해야합니다. 예를 들어 Google 연락처의 경우 다음과 같습니다.

Cursor c = getContentResolver().query(
     RawContacts.CONTENT_URI, 
     new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY }, 
     RawContacts.ACCOUNT_TYPE + "= ?", 
     new String[] { "com.google" }, 
     null); 

ArrayList<String> myContacts = new ArrayList<String>(); 
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY); 
while (c.moveToNext()) 
{ 
    // You can also read RawContacts.CONTACT_ID to read the 
    // ContactsContract.Contacts table or any of the other related ones. 
    myContacts.add(c.getString(contactNameColumn)); 
}