Learning Android I’m trying to find contacts using DISPLAY_NAME selector. I need to find all contacts with given name. Everything goes great using standard query, but falls when I use ContentProviderOperation. I do not understand some of features. When debugging i see exception: Empty values. But, which values I must insert there? Thanks.
op.add(ContentProviderOperation.newAssertQuery(ContactsContract.Contacts.CONTENT_URI)
.withSelection(ContactsContract.Contacts.DISPLAY_NAME + " = '" + name + "'", new String[] {ContactsContract.Contacts._ID})
.build());
try {
result = getContentResolver().applyBatch(ContactsContract.AUTHORITY, op);
} catch (Exception e) {
}
the problem is with your second line of code which should read:
To explain, the withSelection method takes two parameters, the selection string and an array selectionArgs, these are substituted into the selection string during query compilation. So in this example the
?is subtituted for the value ofname. Text qualifiers (single quotes) are automatically embedded at the same time so no additional effort is required