2012-01-09 310 views
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) 

如何正确转换它?

回答

3

望着project page的简单的例子说,你以后解析应该有:

{ 
country_code: 972 
national_number: 39658320 
} 

为了得到它在你想要的格式应与格式NATIONAL格式化:

phoneUtil.format(phone, PhoneNumberFormat.NATIONAL) 

要剥去任何电话号码分隔符看看stripSeparators()android.telephony.PhoneNumberUtils

+0

谢谢!结果现在是:03-965-8320。我会手动删除连字符:D – dor506 2012-01-10 08:37:51