Class PhoneNumberToCarrierMapper

java.lang.Object
com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper

public class PhoneNumberToCarrierMapper extends Object
A phone prefix mapper which provides carrier information related to a phone number.
Author:
Cecilia Roes
  • Method Details

    • getInstance

      public static PhoneNumberToCarrierMapper getInstance()
      Gets a PhoneNumberToCarrierMapper instance to carry out international carrier lookup.

      The PhoneNumberToCarrierMapper is implemented as a singleton. Therefore, calling this method multiple times will only result in one instance being created.

      Returns:
      a PhoneNumberToCarrierMapper instance
    • getNameForValidNumber

      public String getNameForValidNumber(Phonenumber.PhoneNumber number, Locale languageCode)
      Returns a carrier name for the given phone number, in the language provided. The carrier name is the one the number was originally allocated to, however if the country supports mobile number portability the number might not belong to the returned carrier anymore. If no mapping is found an empty string is returned.

      This method assumes the validity of the number passed in has already been checked, and that the number is suitable for carrier lookup. We consider mobile and pager numbers possible candidates for carrier lookup.

      Parameters:
      number - a valid phone number for which we want to get a carrier name
      languageCode - the language code in which the name should be written
      Returns:
      a carrier name for the given phone number
    • getNameForNumber

      public String getNameForNumber(Phonenumber.PhoneNumber number, Locale languageCode)
      Gets the name of the carrier for the given phone number, in the language provided. As per getNameForValidNumber(PhoneNumber, Locale) but explicitly checks the validity of the number passed in.
      Parameters:
      number - the phone number for which we want to get a carrier name
      languageCode - the language code in which the name should be written
      Returns:
      a carrier name for the given phone number, or empty string if the number passed in is invalid
    • getSafeDisplayName

      public String getSafeDisplayName(Phonenumber.PhoneNumber number, Locale languageCode)
      Gets the name of the carrier for the given phone number only when it is 'safe' to display to users. A carrier name is considered safe if the number is valid and for a region that doesn't support mobile number portability.
      Parameters:
      number - the phone number for which we want to get a carrier name
      languageCode - the language code in which the name should be written
      Returns:
      a carrier name that is safe to display to users, or the empty string