ALL, I am trying to execute following piece of code:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query( ContactContract.Contacts.CONTENT_URI, null, "ContactsContract.Contacts.DISPLAY_NAME LIKE '" + name + "'", null, null );
However when running this code, I am getting SQLite exception: "Don't know such file ContactsContract.Contacts.DISPLAY_NAME:, while compiling "....."".
The problem is that I don't know in advance what wi开发者_如何学运维ll "name" contain, hence using "LIKE" clause.
Is there a better way to perform such operation? Or I am just doing it incorrectly?
Thank you in advance for any help.
Or I am just doing it incorrectly?
ContactsContract.Contacts.DISPLAY_NAME
is a Java construct. Use:
Cursor cur = cr.query( ContactContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.DISPLAY_NAME + " LIKE '" + name + "'", null, null );
Or, use positional parameters:
Cursor cur = cr.query( ContactContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?", args, null );
where args
is a one-element string array containing your name
.
精彩评论