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
android sqlite android-cursor android-contacts


source to share


No one has answered this question yet

Check out similar questions:

652
What are the best practices for SQLite on Android?
266
The version of SQLite used in Android?
8
Get the first and last name of a contact instead of one display name?
five
How to sort first and last name in search bar - Sqlite
3
Android SQLite Search using Like doesn't matter for UTF-8 characters
3
SQLite upper () function for international characters
2
Android SQLite SELECT WHERE LIKE unexpected behavior
1
Accent SQLITE Special Sort Function and LIKE Queries
1
SQLite query no longer works in Android 5.0
0
Android search list, String



All Articles
Loading...
X
Show
Funny
Dev
Pics