android同时显示SIM卡和电话联系人 [英] android showing both sim and phone contacts
问题描述
在我的代码中,我应该只显示电话联系人:我关注着以前的帖子,但我仍然显示电话和SIM卡联系人.这是我的代码:
In my code I should display only phone contacts: I followed previous posts but I still display both phone and sim contacts. Here it is my code:
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).
These are all ContactInfo object and they will be showed in a list (listContact, which is an ArrayList).
这对我来说真的很重要,因为我的应用程序仅在电话联系人上有效,而在SIM卡联系人上无效.
It is really important for me because my application works good only on phone contacts and not on sim contacts.
推荐答案
您可以尝试以此替换您的Cursor,以排除sim上的联系人:
You can try to replace your Cursor with this to exclude contacts on 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 修改而来的
I haven't tried this, modified from https://stackoverflow.com/a/4409453/262462
注意:在某些手机上,您可能需要排除其他一些RawContacts.ACCOUNT_TYPE
,例如com.anddroid.contacts.sim
和vnd.sec.contact.sim
,请参见 https://stackoverflow.com/a/13656077/262462
Note: on some phones you may need to exclude few other RawContacts.ACCOUNT_TYPE
like com.anddroid.contacts.sim
and vnd.sec.contact.sim
, see https://stackoverflow.com/a/13656077/262462
这篇关于android同时显示SIM卡和电话联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!