2012-06-15 5 views
0

누군가 계정별로 모든 연락처를받는 방법을 알려줄 수 있습니까? 의미, 연락처가 전화 (사용자가 만든) 또는 Google 및 다른 동기화 소스에서 오는 것인지를 결정하는 조건을 넣고 싶습니다. 지금은 모든 연락처와 모든 동기화 소스의 조합을 얻었 기 때문입니다. 로컬 연락처, 구글 또는 심지어 야후 연락처?계정 유형별 연락처 가져 오기

+0

I을 'cursor = cr.query (ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 시도했지만 Google과 같은 동기화 연락처도 가져옵니다. 전화 연락처 나 전화 번호부 만 필요합니다. – C3pO

답변

1

누군가 계정별로 모든 연락처를받는 방법을 알려줄 수 있습니까?

당신은 특정 계정 유형에 대한 연락처를 검색하기 위해 다음 조각을 사용할 수 있습니다

: 당신이 사용할 수있는

String where = RawContacts.ACCOUNT_TYPE+ "=?"; 
String[] args = { accountType }; 
Cursor contacts = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, where, args, null); 

int numberIndex = contacts.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); 
int displayNameIndex = contacts.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); 
for (contacts.moveToFirst(); !contacts.isAfterLast(); contacts.moveToNext()) { 
    String number = contacts.getString(numberIndex); 
    String displayName = contacts.getString(displayNameIndex); 
    // do something with account contacts 
} 
contacts.close(); 

일반 전화 연락처를 필터링하려면을 (모든 계정에 연결되지 않음) :

String where = RawContacts.ACCOUNT_TYPE+ " IS NULL"; 
+0

남자, 작동하지 않습니다. – Peter