PhoneNumberUtils.formatNumberToE164 不需要的方法结果
PhoneNumberUtils.formatNumberToE164 indesired method result
我试图将 phone 数字格式化为 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);
}
Logcat:
11-11 14:23:19.836 495-495/ma.altaiir.app V/OUTCALL-outgoing:
0612345678
11-11 14:23:19.841 495-495/ma.altaiir.app V/OUTCALL-phone:
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;}
}
Logcat:
11-11 14:23:19.841 495-495/ma.altaiir.app V/COUNTRYISOCODE/NUMB:
ma/0612345678/null
所有这些意味着,该方法只是返回 null,无论我做什么来避免这种情况,这是已知的缺点还是我做错了什么?
最后我使用 libphonenumber 解决了我所有的号码解析问题,但仍然想知道为什么内置方法不起作用!
无论如何,对于任何面临销售解析问题的人,请尝试 https://github.com/googlei18n/libphonenumber
我试图将 phone 数字格式化为 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);
}
Logcat:
11-11 14:23:19.836 495-495/ma.altaiir.app V/OUTCALL-outgoing: 0612345678
11-11 14:23:19.841 495-495/ma.altaiir.app V/OUTCALL-phone: 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;}
}
Logcat:
11-11 14:23:19.841 495-495/ma.altaiir.app V/COUNTRYISOCODE/NUMB: ma/0612345678/null
所有这些意味着,该方法只是返回 null,无论我做什么来避免这种情况,这是已知的缺点还是我做错了什么?
最后我使用 libphonenumber 解决了我所有的号码解析问题,但仍然想知道为什么内置方法不起作用! 无论如何,对于任何面临销售解析问题的人,请尝试 https://github.com/googlei18n/libphonenumber