0
我试图格式化先前E164格式的电话号码,没有国家前缀多项国家格式,我使用PhoneNumberUtils做到这一点:如何使用PhoneNumberUtils库将电话号码格式化为没有国家前缀的国家格式?
public static String getNationalPhone(String phoneE164Formatted) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
String phoneNumber = phoneE164Formatted;
try {
Phonenumber.PhoneNumber numberProto = phoneUtil.parseAndKeepRawInput(phoneE164Formatted, "");
phoneNumber = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
}
return phoneNumber;
}
与该代码我得到了国家前缀我不想要。例如,将这个数字“+526143342293”格式化为国家格式给了我这个结果:“01 614 334 22 93”,其中“01”这是我想压制的。