I have to search a contact based on the phone number. Here is the code that works to fetch contacts. Android API level which I am using is 15
String[] projection = new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor query = mContent.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%" + constraint.toString() + "%'"
,null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
I am able to fetch contact that doesn't have space with in the phone number saved in contacts table. If the phone number has a space between, the above query fails. For example, for a contact, if the phone number is saved as 1234567890 and when I am searching with value 1234, this contact is retrieved. But fails if the contact is saved as "123 456 7890".
Bottom line, when I try to search contacts that has or contains "1234" with phone number, the resulting should return me contacts with phone number "1234567890" and "123 4567 890". As some of the android phones saves phone numbers with space between.
How do I solve this. Any help is appreciated.