I am trying to write a clean bit of code that can list the people in a
1.5/1.6 Contacts data store, and I do not see how I filter out the
cruft that Google throws in (ad hoc "contacts" literally addressed by
other apps and stored, for some reason, in the contact list without a
clear means of discerning them from the real people the user cared to
enter -- the ones that would appear in the contacts app)
I see that in 2.0 or so, "IN_VISIBLE_GROUP" is added as a field which
seems to differentiate these versions, but what existed to accomplish
this before that time?
Here is my code which works in 2.x and fails to keep the chaff out in
1.x, as the selection parameter is unsupported:
final String[] proj = new String[] {
Contacts.People._ID,
Contacts.People.NAME
};
final String selection =
Build.VERSION.SDK_INT < 5 ? null :
ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1";
Cursor people = context.getContentResolver().query(
Contacts.People.CONTENT_URI,
proj,
selection,
null,
Contacts.People.DEFAULT_SORT_ORDER);
if (people != null) {
final int personIdColumn = people
.getColumnIndexOrThrow(Contacts.People._ID);
final int nameColumn = people
.getColumnIndexOrThrow(Contacts.People.NAME);
while (people.moveToNext()) {
if (Thread.interrupted()) {
people.close();
outputList.clear();
throw new InterruptedException();
}
long personId = people.getLong(personIdColumn);
String name = people.getString(nameColumn);
if (name != null) {
outputList.add(new Contact(personId,
name));
}
}
// clean up cursor
people.close();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en