Android : 从联系人中删除国家代码

Android : Delete country code from contact

如何有效地删除或检测联系电话的国家代码?

+213231756 will be 231756 (+231 is the country code of Algeria)

+880171876809 will be 0171876809(+88 is the country code of BD)

举个例子:我创建了一个 string.xml 文件,比如

<string-array name="CountryCodes" >
<item>93,AF</item> 
<item>355,AL</item>
<item>213,DZ</item>

并且 xml 中有将近 190 多个国家代码。 并使用字符串数组检查每个联系电话的时间效率不高。

Is there any efficient solution to detect the country code of a list of phone number.

您可以为此使用 "libphonenumber.jar"。 http://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/7.3.1/

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
    // phone must begin with '+'
    PhoneNumber numberProto = phoneUtil.parse(phone, "");
    int countryCode = numberProto.getCountryCode();
} catch (NumberParseException e) {
    System.err.println("NumberParseException was thrown: " + e.toString());
}