Using LibPhoneNumber google lib in Android
If you're using Android studio use
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.32'
If you want to download the latest JAR file goto
http://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber
Hi Please use this function to pass phone number and country code like india 91
public static String parseContact(String contact, String countrycode) {
PhoneNumber phoneNumber = null;
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
String finalNumber = null;
String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(countrycode));
boolean isValid = false;
PhoneNumberType isMobile = null;
try {
phoneNumber = phoneNumberUtil.parse(contact, isoCode);
isValid = phoneNumberUtil.isValidNumber(phoneNumber);
isMobile = phoneNumberUtil.getNumberType(phoneNumber);
} catch (NumberParseException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
if (isValid
&& (PhoneNumberType.MOBILE == isMobile || PhoneNumberType.FIXED_LINE_OR_MOBILE == isMobile)) {
finalNumber = phoneNumberUtil.format(phoneNumber,
PhoneNumberFormat.E164).substring(1);
}
return finalNumber;
}