2012-07-30 68 views
1

我试图让使用这个简单的查询,其工作方式输入滤波器的完美ignorig情况下的联系人列表,直到我尝试搜索包含cyrillics名称:不区分大小写手机姓名查询

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

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

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

感谢您的回复。

回答

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();