I need to find a contact by phone number. Here is the code that works for extracting contacts. The Android API level I'm 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 can get a contact that does not have a place with a phone number stored in the contact table. If the phone number has a space between them, the request above is not executed. For example, for a contact, if the phone number is saved as 1234567890, and when I search with a value of 1234, this contact will be restored. But it fails if the contact is saved as "123 456 7890."
In the bottom line, when I try to find contacts containing or containing "1234" with a phone number, as a result, we must return me contacts with a phone number of "1234567890" and "123 4567 890". Since some of the android phones store phone numbers with a gap between them.
How can i solve this. Any help is appreciated.
source share