I retrieve the list of phone numbers from the phone using the following code:
Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); while(c.moveToNext()){ Log.d(TAG,"NO.: "+ c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER))); }
In API 16 and above, this will work fine for me, since I want ALL contacts formatted in E 164 format, regardless of how they are stored by the user.
However, for APIs below 16, this code does not work, and I cannot get the E 164 format for all contacts using the following line:
c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
The class "PhoneNumberUtils" cannot be used.
In addition, I cannot use the libphonenumber library to convert numbers to their E 164 format, since I do not know ISO-3166-1 the two-letter country code of the contacts.
Is there a way that I can get a two-digit country code according to ISO 3166-1 for each contact in Android so that I can use the libphonenumber library?
Or is there another solution to reach point 1.?
The numbers received from the phone can be of any format, for example.
- Local: 965XXXXXXX
- National: 0965XXXXXXXX
- International: +91 96 5X XXXXXX
- and others
whereas E 164 + 91XXXXXXXXXX, where 91 is the country code.
Any help would be greatly appreciated!
source share