android: how do I format number as phone with parentheses
I have a number that I need to format as a telephone number. If I do PhoneNumberUtils.formatNumber(numStr); Then I get 888-555-1234 But what I need to get is (888) 555-1234 How do I get the second one? Is there a standard android way? If you know the country for which you want to do it, you can use Google's open source library libphonenumber . Here is how you can format it: String numberStr = "8885551234" PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { PhoneNumber numberProto = phoneUtil.parse(numberStr, "US"); //Since you know the country you can format it as follows: System