I have to read contacts from device which are having valid phone numbers. For that right now I'm using following query.
final Uri contentUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
final String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '" + ("1") + "' AND LENGTH(" + ContactsContract.CommonDataKinds.Phone.NUMBER + ") >= 10";
final String[] projection = null;
final String[] selectionArgs = null;
final String sortOrder = "upper(" + ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID + ") ASC";
Cursor phones = mContentResolver.query(contentUri, projection, selection, selectionArgs, sortOrder);
As you can see in selection
, im querying for entries with HAS_PHONE_NUMBER = 1
and length of phone number >= 10 , to avoid maximum junk contacts while retrieving from itself. It works fine , but the problem is , the saved phone numbers might have special characters like - , ( , )
or a space etc.
Like +9191-91-22-22-55 , +9191-91-(22 22-55) . I need to get this string without non-digits and without country code (last 10 numbers).
For example : +9190-91-22-22-55 as 9091222255
is there any way to retrieve a string field as formatted like this in SQLite? Or is there any effective way to fulfill my requirement? Thanks in advance..