Class PhoneNumberToCarrierMapper


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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PhoneNumberToCarrierMapper getInstance()
      Gets a PhoneNumberToCarrierMapper instance to carry out international carrier lookup.
      java.lang.String getNameForNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number, java.util.Locale languageCode)
      Gets the name of the carrier for the given phone number, in the language provided.
      java.lang.String getNameForValidNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number, java.util.Locale languageCode)
      Returns a carrier name for the given phone number, in the language provided.
      java.lang.String getSafeDisplayName​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number, java.util.Locale languageCode)
      Gets the name of the carrier for the given phone number only when it is 'safe' to display to users.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getNameForValidNumber

        public java.lang.String getNameForValidNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                      java.util.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 java.lang.String getNameForNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                 java.util.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 java.lang.String getSafeDisplayName​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                   java.util.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