Skip to content Skip to sidebar Skip to footer

Only Get Android Contacts That Are Saved To The Phone Or Sim

I am trying to retrieve contacts on an android device that are explicitly saved (i.e. not the ones returned by gmail or Facebook and other apps that save contact-like information).

Solution 1:

Whether or not the contacts appear in the regular contacts is determined by the following property:

ContactsContract.Contacts.IN_VISIBLE_GROUP

I modified one of the queries to account for this and it removed contacts returned that aren't really contacts (such as gmail history, ...etc):

options.setWhere("(" + ContactsContract.Contacts.IN_VISIBLE_GROUP + " = 1 AND " + ContactsContract.Data.CONTACT_ID + " LIKE ? )");

The query in the original question (from the cordova contacts plugin) simply gets the ids that match the provided search term, the query to modify is the one later in the plugin code (more accurately the corresponding getWhere() function was modified to account for the IN_VISIBLE_GROUP property):

Cursorc= mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
            columnsToFetch.toArray(newString[] {}),
            idOptions.getWhere(),
            idOptions.getWhereArgs(),
            ContactsContract.Data.CONTACT_ID + " ASC");

I hosted a modified version of the plugin on my github. Note that my version only works for instances where there is no search term.

Post a Comment for "Only Get Android Contacts That Are Saved To The Phone Or Sim"