在我的代码中,我应该只显示电话联系人:我遵循了之前的帖子,但仍然显示电话和 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对象,它们将显示在一个列表中(listContact,这是一个ArrayList)。
这对我来说非常重要,因为我的应用程序仅适用于电话联系人,而不适用于 SIM 卡联系人。
您可以尝试用此替换光标以排除 sim 上的联系人:
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);
我没试过这个,修改自https://stackoverflow.com/a/4409453/262462 https://stackoverflow.com/a/4409453/262462
注意:在某些手机上,您可能需要排除其他一些RawContacts.ACCOUNT_TYPE
like com.anddroid.contacts.sim
and vnd.sec.contact.sim
, see https://stackoverflow.com/a/13656077/262462 https://stackoverflow.com/a/13656077/262462
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)