public class ShortNumberInfo
extends java.lang.Object
PhoneNumberUtil
.Modifier and Type | Class and Description |
---|---|
static class |
ShortNumberInfo.ShortNumberCost
Cost categories of short numbers.
|
Modifier and Type | Method and Description |
---|---|
boolean |
connectsToEmergencyNumber(java.lang.String number,
java.lang.String regionCode)
Returns true if the given number, exactly as dialed, might be used to connect to an emergency
service in the given region.
|
ShortNumberInfo.ShortNumberCost |
getExpectedCost(Phonenumber.PhoneNumber number)
Gets the expected cost category of a short number (however, nothing is implied about its
validity).
|
ShortNumberInfo.ShortNumberCost |
getExpectedCostForRegion(Phonenumber.PhoneNumber number,
java.lang.String regionDialingFrom)
Gets the expected cost category of a short number when dialed from a region (however, nothing
is implied about its validity).
|
static ShortNumberInfo |
getInstance()
Returns the singleton instance of the ShortNumberInfo.
|
boolean |
isCarrierSpecific(Phonenumber.PhoneNumber number)
Given a valid short number, determines whether it is carrier-specific (however, nothing is
implied about its validity).
|
boolean |
isCarrierSpecificForRegion(Phonenumber.PhoneNumber number,
java.lang.String regionDialingFrom)
Given a valid short number, determines whether it is carrier-specific when dialed from the
given region (however, nothing is implied about its validity).
|
boolean |
isEmergencyNumber(java.lang.CharSequence number,
java.lang.String regionCode)
Returns true if the given number exactly matches an emergency service number in the given
region.
|
boolean |
isPossibleShortNumber(Phonenumber.PhoneNumber number)
Check whether a short number is a possible number.
|
boolean |
isPossibleShortNumberForRegion(Phonenumber.PhoneNumber number,
java.lang.String regionDialingFrom)
Check whether a short number is a possible number when dialed from the given region.
|
boolean |
isSmsServiceForRegion(Phonenumber.PhoneNumber number,
java.lang.String regionDialingFrom)
Given a valid short number, determines whether it is an SMS service (however, nothing is
implied about its validity).
|
boolean |
isValidShortNumber(Phonenumber.PhoneNumber number)
Tests whether a short number matches a valid pattern.
|
boolean |
isValidShortNumberForRegion(Phonenumber.PhoneNumber number,
java.lang.String regionDialingFrom)
Tests whether a short number matches a valid pattern in a region.
|
public static ShortNumberInfo getInstance()
public boolean isPossibleShortNumberForRegion(Phonenumber.PhoneNumber number, java.lang.String regionDialingFrom)
isValidShortNumberForRegion(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, java.lang.String)
.number
- the short number to checkregionDialingFrom
- the region from which the number is dialedpublic boolean isPossibleShortNumber(Phonenumber.PhoneNumber number)
isValidShortNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)
. See #isPossibleShortNumberForRegion(PhoneNumber, String)
for details.number
- the short number to checkpublic boolean isValidShortNumberForRegion(Phonenumber.PhoneNumber number, java.lang.String regionDialingFrom)
number
- the short number for which we want to test the validityregionDialingFrom
- the region from which the number is dialedpublic boolean isValidShortNumber(Phonenumber.PhoneNumber number)
#isValidShortNumberForRegion(PhoneNumber, String)
for details.number
- the short number for which we want to test the validitypublic ShortNumberInfo.ShortNumberCost getExpectedCostForRegion(Phonenumber.PhoneNumber number, java.lang.String regionDialingFrom)
isValidShortNumberForRegion(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, java.lang.String)
. Note that emergency numbers
are always considered toll-free. Example usage:
// 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.
}
number
- the short number for which we want to know the expected cost categoryregionDialingFrom
- the region from which the number is dialedpublic ShortNumberInfo.ShortNumberCost getExpectedCost(Phonenumber.PhoneNumber number)
#getExpectedCostForRegion(PhoneNumber, String)
. However, if the country
calling code is shared by multiple regions, then it returns the highest cost in the sequence
PREMIUM_RATE, UNKNOWN_COST, STANDARD_RATE, TOLL_FREE. The reason for the position of
UNKNOWN_COST in this order is that if a number is UNKNOWN_COST in one region but STANDARD_RATE
or TOLL_FREE in another, its expected cost cannot be estimated as one of the latter since it
might be a PREMIUM_RATE number.
For example, if a number is STANDARD_RATE in the US, but TOLL_FREE in Canada, the expected cost returned by this method will be STANDARD_RATE, since the NANPA countries share the same country calling code.
Note: If the region from which the number is dialed is known, it is highly preferable to call
#getExpectedCostForRegion(PhoneNumber, String)
instead.
number
- the short number for which we want to know the expected cost categorypublic boolean connectsToEmergencyNumber(java.lang.String number, java.lang.String regionCode)
This method accepts a string, rather than a PhoneNumber, because it needs to distinguish cases such as "+1 911" and "911", where the former may not connect to an emergency service in all cases but the latter would. This method takes into account cases where the number might contain formatting, or might have additional digits appended (when it is okay to do that in the specified region).
number
- the phone number to testregionCode
- the region where the phone number is being dialedpublic boolean isEmergencyNumber(java.lang.CharSequence number, java.lang.String regionCode)
This method takes into account cases where the number might contain formatting, but doesn't
allow additional digits to be appended. Note that isEmergencyNumber(number, region)
implies connectsToEmergencyNumber(number, region)
.
number
- the phone number to testregionCode
- the region where the phone number is being dialedpublic boolean isCarrierSpecific(Phonenumber.PhoneNumber number)
isValidShortNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)
or
isValidShortNumberForRegion(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, java.lang.String)
.number
- the valid short number to checkpublic boolean isCarrierSpecificForRegion(Phonenumber.PhoneNumber number, java.lang.String regionDialingFrom)
isValidShortNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)
or isValidShortNumberForRegion(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, java.lang.String)
. Returns false if the
number doesn't match the region provided.number
- the valid short number to checkregionDialingFrom
- the region from which the number is dialedpublic boolean isSmsServiceForRegion(Phonenumber.PhoneNumber number, java.lang.String regionDialingFrom)
isValidShortNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)
or isValidShortNumberForRegion(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, java.lang.String)
. Returns false if the number doesn't match the region provided.number
- the valid short number to checkregionDialingFrom
- the region from which the number is dialedCopyright © 2017 Google. All Rights Reserved.