Issue
I am trying to format a phone number to E164 , in vain :
//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
Formatting method :
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
All this means , the method is just returning null whatever I do to avoid this, is this known drawback or it is something I do wrong ?
Solution
Finally i ended up using libphonenumber wich resolved all my number parsing problems, but still wondering why builin method do not work ! Anyways, for any one facing the sale parsing problems, try https://github.com/googlei18n/libphonenumber
Answered By - Altaiir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.