Android - Sqlite search using LIKE and UPPER for international characters

I am currently trying to run a search on a contacts database and where the value I am passing matches the display name in contacts, I want to return a cursor with the number of contacts that match.

This currently works fine except for international characters, this is how my code currently looks with the constraint being the CharSequence taken from the EditText:

String[] PROJECTION = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.HAS_PHONE_NUMBER,
        };

String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

public Cursor runQuery(CharSequence constraint) {

        String SELECTION = "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ")" 
            + " LIKE UPPER('%" + constraint+ "%') " + "and " + ContactsContract.Contacts.DISPLAY_NAME + " IS NOT NULL"
         + " AND " + ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, 
                    PROJECTION, SELECTION, null, sortOrder);

    return cur; 
}

      

As I said, this works great as I want the search to be case insensitive, so the user does not need to enter the exact name, the normal English name works fine, but as soon as international characters are entered, the search becomes case sensitive ...

I've done some research that suggests sqlite requires the addition of an ICU in order to do this work, which is missing on Android. Or use sorting when inserting into the database. However, since I am only reading from a contacts content provider, this is not an option for me.

Does anyone know how to get the search in the above code to work with international characters if it is case insensitive?

+3


source to share





All Articles