如何有效地删除或检测联系电话的国家代码?
[+ 213231756将为231756(+231是阿尔及利亚的国家代码)
+ 880171876809将为0171876809(+88是BD的国家代码)
例如,我创建一个类似的string.xml文件
<string-array name="CountryCodes" >
<item>93,AF</item>
<item>355,AL</item>
<item>213,DZ</item>
并且xml中几乎有190多个国家/地区代码。并使用字符串数组检查每个联系电话的时间都不高效。
是否有任何有效的解决方案可以检测电话号码列表的国家/地区代码。
您可以为此使用“ 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());
}