1

我正在尝试使用libphonenumber谷歌库将数字从国际转换为本地。

国际号码代表为:“+97239658320”

本地号码(在以色列是):“039658320”

http://code.google.com/p/libphonenumber/

    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

    PhoneNumber phone = null;

    try
    {
        phone = PhoneNumberUtil.getInstance().parse("+97239658320", null);
    }

    catch (NumberParseException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但是,在“电话”中,结果是:

Country Code: 972 National Number: 39658320 (without the leading zero)

如何正确转换它?

4

1 回答 1

3

查看项目页面的快速示例说您在解析后应该有:

{
country_code: 972
national_number: 39658320
}

要以您想要的格式获取它,您应该使用 format 对其进行格式化NATIONAL

phoneUtil.format(phone, PhoneNumberFormat.NATIONAL)

要删除任何电话号码分隔符,请查看android.telephony.PhoneNumberUtils中的stripSeparators()

于 2012-01-09T20:01:56.873 回答