How do I make a case insensitive query with ContentResolver in Android?

前端 未结 3 819
半阙折子戏
半阙折子戏 2021-02-08 04:45

My goal is to get all rows from native db with a specific email address on Android Gingerbread and above.

This query gets only the rows where the case also matches.

3条回答
  •  独厮守ぢ
    2021-02-08 05:32

    Please try (I suppose that mail is String object):

    Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            new String[] {Contacts._ID}, "lower("+ContactsContract.CommonDataKinds.Email.ADDRESS + ")=lower('"+ email +"')",
            null, null);
    

    or

    Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            new String[] {Contacts._ID}, "lower("+ContactsContract.CommonDataKinds.Email.ADDRESS + ")=lower('"+ email +"')",
            new String[] {}, null);
    

提交回复
热议问题