public class ShortNumberInfo extends 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(String number,
String regionCode)
Returns true if the number 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(String shortNumber,
String regionDialingFrom)
Gets the expected cost category of a short number when dialled 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 |
isEmergencyNumber(String number,
String regionCode)
Returns true if the 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(String shortNumber,
String regionDialingFrom)
Check whether a short number is a possible number when dialled from a region, given the number
in the form of a string, and the region where the number is dialed from.
|
boolean |
isValidShortNumber(Phonenumber.PhoneNumber number)
Tests whether a short number matches a valid pattern.
|
boolean |
isValidShortNumberForRegion(String shortNumber,
String regionDialingFrom)
Tests whether a short number matches a valid pattern in a region.
|
public static ShortNumberInfo getInstance()
public boolean isPossibleShortNumberForRegion(String shortNumber, String regionDialingFrom)
isValidShortNumberForRegion(java.lang.String, java.lang.String).shortNumber - the short number to check as a stringregionDialingFrom - the region from which the number is dialedpublic boolean isPossibleShortNumber(Phonenumber.PhoneNumber number)
isValidShortNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber). See isPossibleShortNumberForRegion(String, String) for details.number - the short number to checkpublic boolean isValidShortNumberForRegion(String shortNumber, String regionDialingFrom)
shortNumber - the short number to check as a stringregionDialingFrom - the region from which the number is dialedpublic boolean isValidShortNumber(Phonenumber.PhoneNumber number)
isValidShortNumberForRegion(String, String) for details.number - the short number for which we want to test the validitypublic ShortNumberInfo.ShortNumberCost getExpectedCostForRegion(String shortNumber, String regionDialingFrom)
isValidShortNumberForRegion. Note that emergency numbers
are always considered toll-free. Example usage:
ShortNumberInfo shortInfo = ShortNumberInfo.getInstance();
String shortNumber = "110";
String regionCode = "FR";
if (shortInfo.isValidShortNumberForRegion(shortNumber, regionCode)) {
ShortNumberInfo.ShortNumberCost cost = shortInfo.getExpectedCostForRegion(shortNumber,
regionCode);
// Do something with the cost information here.
}shortNumber - the short number for which we want to know the expected cost category,
as a stringregionDialingFrom - the region from which the number is dialedpublic ShortNumberInfo.ShortNumberCost getExpectedCost(Phonenumber.PhoneNumber number)
getExpectedCostForRegion(String, 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(String, String) instead.number - the short number for which we want to know the expected cost categorypublic boolean connectsToEmergencyNumber(String number, String regionCode)
number - the phone number to testregionCode - the region where the phone number is being dialedpublic boolean isEmergencyNumber(String number, String regionCode)
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(java.lang.String, java.lang.String).number - the valid short number to checkCopyright © 2014 Google. All Rights Reserved.