Formatting of number from contacts

2019-07-21 08:25发布

问题:

I'm writing some sms application for android and i have a problem. I send sms from one emulator to another. That sms has "15555215556" as phone number it was sent from. When i save that number to contacts, it's saved in "+1-555-521-5556" format. Next, when my app search phone book to find matching phone number, it couldn't find any, because "15555215556" is not the same as "+1-555-521-5556" (in phone book).

Is there any built-in class that can properly format given phone number?

回答1:

There is the phone number util class

http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html

otherwise you can use libphoneumber

http://code.google.com/p/libphonenumber/

only 140 KB