2
在我的代码中,我应该只显示手机通讯录:我跟着以前的帖子,但我仍然显示手机和SIM卡的联系人。这是我的代码:android同时显示模拟和手机通讯录
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卡联系人不同ACCOUNT_TYPE,所以你不能用相同的代码F排除它们或所有电话。无论如何感谢您的答案! – moo 2013-03-08 15:20:18
@moo我编辑了我的答案以包含多个ACCOUNT_TYPE。如果您需要排除更多,只需使用与此处相同的逻辑添加它们即可。 – Kuitsi 2013-03-11 12:17:49
您是否也知道手机通讯录的这些值?我目前只知道'vnd.sec.contact.phone'和'com.sonyericsson.localcontacts' ... – prom85 2015-05-28 09:22:56