3

I need to determine the national carrier code (not the country code) of any phone number, using libphonenumber Java SDK. How can I do this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
RedEagle
  • 4,418
  • 9
  • 41
  • 64

2 Answers2

4

This should help your case - PhoneNumberToCarrierMapper

In the PhoneNumberToCarrierMapper class there is a method:

String getNameForValidNumber(PhoneNumber number, Locale languageCode)

This should give your the carrier code.
You can see the source code of that method in the related GitHub repository here.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Srikanth Balaji
  • 2,638
  • 4
  • 18
  • 31
0

libphonenumber-8.13.6 doesn't seem to come packaged with PhoneNumberToCarrierMapper class. The import will not work for com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper

I had to add a separate jar to my build path to get this class to successfully import. If you are using maven, you would just need to add a new dependency to your pom file.

https://repo1.maven.org/maven2/com/googlecode/libphonenumber/carrier/

Ramster
  • 31
  • 1
  • 3