2013-02-16 2 views
2

제 코드에서는 전화 연락처 만 표시해야합니다 : 이전 게시물을 따라 갔지만 여전히 전화와 SIM 연락처를 모두 표시합니다.안드로이드는 심과 전화 접촉을 모두 보여줍니다

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 

String columIndex = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME; 
String columIndexId = ContactsContract.CommonDataKinds.Phone.CONTACT_ID; 
String numIndex = ContactsContract.CommonDataKinds.Phone.NUMBER; 

Cursor cursor = getContentResolver().query(uri, null, null, null,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+" ASC"); 

if(cursor!=null){ 
    while(cursor.moveToNext()) { 
     ContactInfo ci = new ContactInfo(); 
     ci.setIdContact(Integer.parseInt(cursor.getString(cursor.getColumnIndex(columIndexId)))); 
     ci.setName(cursor.getString(cursor.getColumnIndex(columIndex))); 
     ci.setNumberTel(cursor.getString(cursor.getColumnIndex(numIndex))); 
     //if(!cursor.getString(cursor.getColumnIndex(columIndex)).equalsIgnoreCase(nome)) 
     listContact.add(ci); 
    } 
    cursor.close(); 

} 

이 모든 CONTACTINFO 객체이며, 그들이리스트 (ArrayList에이고의 listContact)에서 보여됩니다 여기 내 코드입니다.

내 응용 프로그램이 전화 연락처에서만 작동하고 sim 연락처에서는 작동하지 않기 때문에 정말 중요합니다.

답변

3
당신은 SIM에 연락처를 제외이 당신의 커서를 대체하기 위해 시도 할 수

: https://stackoverflow.com/a/4409453/262462

주에서 수정 난이 시도하지 않은

import android.provider.ContactsContract.RawContacts; 

Cursor cursor = getContentResolver().query(
    RawContacts.CONTENT_URI, 
    new String[] { RawContacts._ID, RawContacts.ACCOUNT_TYPE }, 
    RawContacts.ACCOUNT_TYPE + " <> 'com.android.contacts.sim' AND " 
     + RawContacts.ACCOUNT_TYPE + " <> 'com.anddroid.contacts.sim' AND " // HTC 
     + RawContacts.ACCOUNT_TYPE + " <> 'vnd.sec.contact.sim' AND " 
     + RawContacts.ACCOUNT_TYPE + " <> 'USIM Account' ", 
     null, 
     null); 

을 : 일부 휴대 전화에서 제외해야 할 수 있습니다를 기타 RawContacts.ACCOUNT_TYPEcom.anddroid.contacts.simvnd.sec.contact.sim입니다. https://stackoverflow.com/a/13656077/262462

+0

안녕하세요, 저는 시도했지만 Sim 연락처와 다른 Account_type이 있으므로 동일한 코드 f를 사용하여 제외 할 수 없습니다. 또는 모든 전화. 어쨌든 당신의 대답에 감사드립니다! – moo

+0

@moo 여러 개의 ACCOUNT_TYPE을 포함하도록 답을 수정했습니다. 더 이상 제외해야하는 경우 여기와 같은 논리를 사용하여 추가하십시오. – Kuitsi

+0

전화 연락처의 값도 알고 있습니까? 저는 현재'vnd.sec.contact.phone'과'com.sonyericsson.localcontacts'만을 알고 있습니다 ... – prom85

관련 문제