2016-11-11 4 views
0

私は無駄では、E164に電話番号をフォーマットしようとしています:PhoneNumberUtils.formatNumberToE164 indesired方法結果

//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。アプリ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;} 
} 

Logcat:

11-11 14:23:19.841 495から495/ma.altaiir.app V/COUNTRYISOCODE/NUMB: MA/0612345678 /ヌル

すべてこの手段メソッドは、これを避けるために何をしてもnullを返すだけです。これは既知の欠点ですか、それとも私が間違っていることですか?

答えて

0

最後に私はlibphonenumberを使ってすべての番号解析の問題を解決しましたが、なぜbuilinメソッドがうまくいかないのか疑問に思っていました。 とにかく、販売解析の問題に直面している人は、https://github.com/googlei18n/libphonenumber

+0

と答えてください – marmor

関連する問題