If you already have complete mobile number in a specific format e.g. +91-99xxxxxxxx and want to fetch country code = IN, then here is a reference to a solution.
Use a lib in your gradle.
//Phone Utils lib.
implementation 'com.googlecode.libphonenumber:libphonenumber:7.0'
And the code which will help to find the country code and other information is as below.
PhoneNumberUtil utils = PhoneNumberUtil.getInstance();
try {
for (String region : utils.getSupportedRegions()) {
// Check whether it's a valid number.
boolean isValid = utils.isPossibleNumber(mobileNo, region);
if (isValid) {
Phonenumber.PhoneNumber number = util.parse(mobileNo, region);
// Check whether it's a valid number for the given region.
isValid = utils.isValidNumberForRegion(number, region);
if (isValid) {
Log.d("Region:" , region); // IN
Log.d("Phone Code", number.getCountryCode()); // 91
Log.d("Phone No.", number.getNationalNumber()); // 99xxxxxxxxxx
}
}
}
} catch (NumberParseException e) {
e.printStackTrace();
}