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