我试图将一个电话号码格式化为E164,但没有结果:
//Detects outgoing call :
private class MyOutCallsReceiver extends BroadcastReceiver{
public MyOutCallsReceiver() {super();}
@Override
public void onReceive(Context context, Intent intent) {
String outgoingNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.v("OUTCALL-outgoing",outgoingNumber);
String phone = MyApplication.TryFormatPhoneNumberToE164(outgoingNumber);
Log.v("OUTCALL-phone",phone);
}逻辑猫:
11-11 14:23:19.836 495-495/ma.altaiir.app V/出电话: 0612345678 11-11 14:23:19.841 495-495/ma.altaiir.app V/出电话: 0612345678
格式化方法:
public static String TryFormatPhoneNumberToE164(String phone){
String result = PhoneNumberUtils.formatNumberToE164(phone,_CountryIsoCode);
if(result == null){result = PhoneNumberUtils.formatNumberToE164(PhoneNumberUtils.normalizeNumber(phone),_CountryIsoCode);}
Log.v("COUNTRYISOCODE/NUMB",_CountryIsoCode + "/" + phone + "/" + result);
if(result == null){return phone;}else{ return result;}
}逻辑猫:
11-11 14:23:19.841 495-495/ma.altaiir.app V/COUNTRYISOCODE/NUMB: ma/0612345678/null
所有这一切意味着,方法只是返回空,无论我做什么来避免这一点,这是已知的缺点,还是它是我做错了什么?
发布于 2016-11-12 14:04:30
最后,我使用libphonenumber解决了所有的数字解析问题,但仍然想知道为什么builin方法不能工作!无论如何,对于任何面临销售解析问题的人,请尝试使用https://github.com/googlei18n/libphonenumber
https://stackoverflow.com/questions/40550129
复制相似问题