Created
September 25, 2014 18:20
-
-
Save ktoraskartwilio/ae137abcdf17cb5e930b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.i18n.phonenumbers.CountryCodeToRegionCodeMap; | |
import com.google.i18n.phonenumbers.NumberParseException; | |
import com.google.i18n.phonenumbers.PhoneNumberUtil; | |
import com.google.i18n.phonenumbers.Phonenumber; | |
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; | |
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource; | |
public static String lookupCountryLibPhoneNumber(String phonenumber) { | |
String countryKey = null; | |
String countryName = null; | |
System.out.println("PhoneNumber: "+phonenumber); | |
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); | |
try { | |
PhoneNumber phoneNumber = phoneNumberUtil.parse(phonenumber, null); | |
int countryKeyInt = phoneNumber.getCountryCode(); | |
// lookup the country now | |
countryKey = phoneNumberUtil.getRegionCodeForCountryCode(countryKeyInt); | |
countryName = getCountryName(countryKey); | |
} catch (NumberParseException e1) { | |
// TODO Auto-generated catch block | |
e1.printStackTrace(); | |
} | |
return countryName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment