Package com.google.i18n.phonenumbers
Class PhoneNumberToCarrierMapper
java.lang.Object
com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper
A phone prefix mapper which provides carrier information related to a phone number.
- Author:
- Cecilia Roes
-
Method Summary
Modifier and TypeMethodDescriptionstatic PhoneNumberToCarrierMapper
Gets aPhoneNumberToCarrierMapper
instance to carry out international carrier lookup.getNameForNumber
(Phonenumber.PhoneNumber number, Locale languageCode) Gets the name of the carrier for the given phone number, in the language provided.getNameForValidNumber
(Phonenumber.PhoneNumber number, Locale languageCode) Returns a carrier name for the given phone number, in the language provided.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.
-
Method Details
-
getInstance
Gets aPhoneNumberToCarrierMapper
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
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 namelanguageCode
- the language code in which the name should be written- Returns:
- a carrier name for the given phone number
-
getNameForNumber
Gets the name of the carrier for the given phone number, in the language provided. As pergetNameForValidNumber(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 namelanguageCode
- 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
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 namelanguageCode
- 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
-