How to display only phone contacts (excluding SIM card contacts)

I create a user interface where I need to show the phone's contact list as a list.

I use ContactsContract.Data and CursorLoader to load data, and then bind the cursor to a user adapter (extended from SimpleCursorAdapter ).

The problem is that I cannot figure out how to filter the SIM card contacts; on the test phone I have the same contacts on the phone, as well as on the SIM card, which leads to duplicate entries in the list. If I remove the SIM, the duplicates will disappear.

How can I disconnect this filter from the contacts of the SIM card? I am looking for a way to get data using 1 query.

This is how I upload my data at the moment:

 Uri queryUri = ContactsContract.Data.CONTENT_URI; String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Data.MIMETYPE, ContactsContract.RawContacts.ACCOUNT_TYPE }; selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = 1 AND IS_PRIMARY = 1 AND MIMETYPE = '" + Phone.CONTENT_ITEM_TYPE + "'"; cursorLoader = new CursorLoader(getActivity(), queryUri, projection, selection, null, ContactsContract.Contacts.DISPLAY_NAME); cursor = cursorLoader.loadInBackground(); //setup adapter, bind to listview etc.. 
+2
source share
1 answer

It revealed:

Basically you need:

 Uri queryUri = ContactsContract.Contacts.CONTENT_URI; 

This will correspond to the user's address book setting - if the user has disabled the display of SIM card contacts, the query results automatically exclude SIM card contacts.

Hope this helps someone else.

+1
source

Source: https://habr.com/ru/post/1241408/


All Articles