Package 

Class ShortNumberInfo


  • 
    public class ShortNumberInfo
    
                        

    Methods for getting information about short phone numbers, such as short codes and emergency numbers. Note that most commercial short numbers are not handled here, but by the PhoneNumberUtil.

    • Method Detail

      • isPossibleShortNumber

         boolean isPossibleShortNumber(Phonenumber.PhoneNumber number)

        Check whether a short number is a possible number. If a country calling code is shared bymultiple regions, this returns true if it's possible in any of them. This provides a morelenient check than isValidShortNumber. See for details.

        Parameters:
        number - the short number to check
      • isValidShortNumberForRegion

         boolean isValidShortNumberForRegion(Phonenumber.PhoneNumber number, String regionDialingFrom)

        Tests whether a short number matches a valid pattern in a region. Note that this doesn't verifythe number is actually in use, which is impossible to tell by just looking at the numberitself.

        Parameters:
        number - the short number for which we want to test the validity
        regionDialingFrom - the region from which the number is dialed
      • isValidShortNumber

         boolean isValidShortNumber(Phonenumber.PhoneNumber number)

        Tests whether a short number matches a valid pattern. If a country calling code is shared bymultiple regions, this returns true if it's valid in any of them. Note that this doesn't verifythe number is actually in use, which is impossible to tell by just looking at the numberitself. See isValidShortNumberForRegion for details.

        Parameters:
        number - the short number for which we want to test the validity
      • getExpectedCostForRegion

         ShortNumberInfo.ShortNumberCost getExpectedCostForRegion(Phonenumber.PhoneNumber number, String regionDialingFrom)

        Gets the expected cost category of a short number when dialed from a region (however, nothingis implied about its validity). If it is important that the number is valid, then its validitymust first be checked using isValidShortNumberForRegion. Note that emergency numbersare always considered toll-free. Example usage:

        {@code * // The region for which the number was parsed and the region we subsequently check against * // need not be the same. Here we parse the number in the US and check it for Canada. * PhoneNumber number = phoneUtil.parse("110", "US"); * ... * String regionCode = "CA"; * ShortNumberInfo shortInfo = ShortNumberInfo.getInstance(); * if (shortInfo.isValidShortNumberForRegion(shortNumber, regionCode)) { * ShortNumberCost cost = shortInfo.getExpectedCostForRegion(number, regionCode); * // Do something with the cost information here. * }}
        Parameters:
        number - the short number for which we want to know the expected cost category
        regionDialingFrom - the region from which the number is dialed
      • getExpectedCost

         ShortNumberInfo.ShortNumberCost getExpectedCost(Phonenumber.PhoneNumber number)

        Gets the expected cost category of a short number (however, nothing is implied about itsvalidity). If the country calling code is unique to a region, this method behaves exactly thesame as getExpectedCostForRegion. However, if the countrycalling code is shared by multiple regions, then it returns the highest cost in the sequencePREMIUM_RATE, UNKNOWN_COST, STANDARD_RATE, TOLL_FREE. The reason for the position ofUNKNOWN_COST in this order is that if a number is UNKNOWN_COST in one region but STANDARD_RATEor TOLL_FREE in another, its expected cost cannot be estimated as one of the latter since itmight be a PREMIUM_RATE number.

        For example, if a number is STANDARD_RATE in the US, but TOLL_FREE in Canada, the expectedcost returned by this method will be STANDARD_RATE, since the NANPA countries share the samecountry calling code.

        Note: If the region from which the number is dialed is known, it is highly preferable to call getExpectedCostForRegion instead.

        Parameters:
        number - the short number for which we want to know the expected cost category
      • connectsToEmergencyNumber

         boolean connectsToEmergencyNumber(String number, String regionCode)

        Returns true if the given number, exactly as dialed, might be used to connect to an emergencyservice in the given region.

        This method accepts a string, rather than a PhoneNumber, because it needs to distinguishcases such as "+1 911" and "911", where the former may not connect to an emergency service inall cases but the latter would. This method takes into account cases where the number mightcontain formatting, or might have additional digits appended (when it is okay to do that inthe specified region).

        Parameters:
        number - the phone number to test
        regionCode - the region where the phone number is being dialed
      • isEmergencyNumber

         boolean isEmergencyNumber(CharSequence number, String regionCode)

        Returns true if the given number exactly matches an emergency service number in the givenregion.

        This method takes into account cases where the number might contain formatting, but doesn'tallow additional digits to be appended. Note that {@code isEmergencyNumber(number, region)} implies {@code connectsToEmergencyNumber(number, region)}.

        Parameters:
        number - the phone number to test
        regionCode - the region where the phone number is being dialed
      • isCarrierSpecific

         boolean isCarrierSpecific(Phonenumber.PhoneNumber number)

        Given a valid short number, determines whether it is carrier-specific (however, nothing isimplied about its validity). Carrier-specific numbers may connect to a different end-point, ornot connect at all, depending on the user's carrier. If it is important that the number isvalid, then its validity must first be checked using isValidShortNumber or isValidShortNumberForRegion.

        Parameters:
        number - the valid short number to check
      • isCarrierSpecificForRegion

         boolean isCarrierSpecificForRegion(Phonenumber.PhoneNumber number, String regionDialingFrom)

        Given a valid short number, determines whether it is carrier-specific when dialed from thegiven region (however, nothing is implied about its validity). Carrier-specific numbers mayconnect to a different end-point, or not connect at all, depending on the user's carrier. Ifit is important that the number is valid, then its validity must first be checked using isValidShortNumber or isValidShortNumberForRegion. Returns false if thenumber doesn't match the region provided.

        Parameters:
        number - the valid short number to check
        regionDialingFrom - the region from which the number is dialed
      • isSmsServiceForRegion

         boolean isSmsServiceForRegion(Phonenumber.PhoneNumber number, String regionDialingFrom)

        Given a valid short number, determines whether it is an SMS service (however, nothing isimplied about its validity). An SMS service is where the primary or only intended usage is toreceive and/or send text messages (SMSs). This includes MMS as MMS numbers downgrade to SMS ifthe other party isn't MMS-capable. If it is important that the number is valid, then itsvalidity must first be checked using isValidShortNumber or . Returns false if the number doesn't match the region provided.

        Parameters:
        number - the valid short number to check
        regionDialingFrom - the region from which the number is dialed