I'm trying to make a filtering query:
public Cursor runQuery(CharSequence constraint) {
return getActivity().getContentResolver().query(
Phone.CONTENT_URI,
new String[] {Phone.DISPLAY_NAME, Phone.NUMBER, Phone.TYPE, Phone._ID },
Phone.DISPLAY_NAME + " LIKE '" + constraint + "%'",// <-- problem here
null,
Phone.DISPLAY_NAME);
}
But LIKE operator works in case-sensitive way for non-ascii chars (as SQLite docs says). Is there a way to make case-insensitive LIKE? (p.s. i test on russian symbols)
Things that not works:
Need help or advice. Thank you.
I haven't solve a problem of case-insensitive LIKE, but I found a solution for my specific situation, and it works even better than i expected :) May be it'll be usefull for you. So, to filter contacts with phones by name use Phone.CONTENT_FILTER_URI
@Override
public Cursor runQuery(CharSequence constraint) {
return mContext.getContentResolver().query(
Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint.toString())),
//PROJECTION
new String[] {
Phone._ID,
Phone.DISPLAY_NAME,
Phone.NUMBER,
Phone.TYPE,
Phone.PHOTO_ID},
//WHERE
ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1",
null,
//ORDER BY
null);
}
This provider perform advanced case-insensitive filtering and also filters by phone number if constraint is number :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With