I able to detect incoming calls in android but problem is that I want to know to the country code of that phone number so that I can analyze whether it is a national or international number. I know about libphonenumber but It needs to know region code before hand to get the country code as shown in the example
String swissNumberStr = "044 668 18 00";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "CH");
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
it already knows to put "CH"
as a parameter. but we don't know if the number is to known to us then how we can analyze that number.
As long as it is not a regional number (in which case it is just a plain number and no lib in this world could determine where it is from) you can specify
"ZZ"
ornull
for the second parameter ofparse
.This is what the documentation says:
After you where able to create an instace of
PhoneNumber
you can simply callgetRegionCodeForNumber
as shown below.