1

我正在尝试使用这个简单的查询来获取联系人列表,它可以完全忽略输入过滤器的情况,直到我尝试搜索包含西里尔字母的名称:

Cursor c = this.getContext().getContentResolver().query(Phone.CONTENT_URI,
            PHONE_PROJECTION, Phone.DISPLAY_NAME + " LIKE '%"+filter+"%'", null,     Phone.LAST_TIME_CONTACTED + " DESC");

问题是这段代码返回包含西里尔字母的名称仅用于完全匹配 - 所以它对西里尔字母区分大小写。我也想让搜索对西里尔字母不区分大小写。应用程序在最低 SDK 2.1 上运行

系统本身(在 4.0 ICS 上测试)能够在联系人列表中进行不区分大小写的搜索(默认系统应用程序 - 人员)。

感谢您的回复。

4

1 回答 1

0

修复了你的代码,确保处理其余的我做了一个例子这是固定的代码:

 String name = "contact_name_to_search_for"
 Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
            null,"DISPLAY_NAME" + " LIKE '%"+name+"%'", null,
            ContactsContract.CommonDataKinds.Phone.LAST_TIME_CONTACTED + " DESC");

例如,这是我制作的完整处理代码

String name = "contact_name_to_search_for"
        ContentResolver cr = getContentResolver();
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
            null,"DISPLAY_NAME" + " LIKE '%"+name+"%'", null,
            ContactsContract.CommonDataKinds.Phone.LAST_TIME_CONTACTED + " DESC");
    if (cursor.moveToFirst()) {
        String contactId =
                cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)).toLowerCase();
        Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId.toLowerCase(), null, null);
        while (phones.moveToNext()) {
            String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            int type = phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
            switch (type) {
                case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
                    Toast.makeText(getApplicationContext(), number+" Home number",Toast.LENGTH_SHORT ).show();
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
                    Toast.makeText(getApplicationContext(), number+" Mobile number",Toast.LENGTH_SHORT ).show();
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
                    Toast.makeText(getApplicationContext(), number+" Work number",Toast.LENGTH_SHORT ).show();
                    break;
            }
        }
        phones.close();
    }
    cursor.close();
于 2014-05-22T20:29:19.687 回答