public class TelephoneNumberUtils extends Object
Applications can use the methods in this class to deal with phone numbers.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
BCD_EXT_TYPE_CALLED_PARTY |
Indicates the called party BCD number type.
|
static int |
BCD_EXT_TYPE_EF_ADN |
Indicates the abbreviated dialing number type.
|
static int |
INTERNATIONAL_TON_VALUE |
Indicates the international number type.
|
static char |
PAUSE |
'p' - Indicates the PAUSE character defined in the ETSI GSM specifications.
|
static int |
UNKNOWN_TON_VALUE |
Indicates an unknown number type.
|
static char |
WAIT |
'w' - Indicates the WAIT character defined in the ETSI GSM specifications.
|
static char |
WILD |
'n' - Indicates the WILD character defined in the ETSI GSM specifications.
|
| 构造器 | 说明 |
|---|---|
TelephoneNumberUtils() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static String |
changeKeypadLettersToDigits(String data) |
Converts any alphabetic letter ([A-Z] or [a-z]) in a phone number to an equivalent digit
according to the phone keyboard mapping described in ITU E.161 and ISO/IEC 9995-8.
|
static boolean |
comparePhoneNumbers(String phoneNumberA,
String phoneNumberB) |
Compares two phone numbers.
|
static String |
convertCalledPartyBCDToStringWithoutTOA(byte[] data,
int offset,
int calledPartyBCDNumberLength,
int bcdExtendedType) |
Converts a called party BCD number without the TOA field.
|
static String |
convertCalledPartyBCDToStringWithTOA(byte[] data,
int offset,
int calledPartyBCDNumberLength,
int bcdExtendedType) |
Converts a called party binary-coded decimal (BCD) number carrying the TOA field.
|
static String |
convertPhoneNumber(String phoneNumber) |
Converts the character 'p' or 'P' in a phone number to a comma (,),
and the character "w" or "W" to a semicolon (;).
|
static String |
extractNetworkAddressPortion(String phoneNumber) |
Extracts the network address and standardizes it by filtering out separators.
|
static String |
extractNetworkAddressPortionPlus(String phoneNumber) |
Extracts the network address from a phone number and standardizes it
by filtering out separators (excluding the plus sign (+), if available).
|
static String |
extractPostDialPortion(String phoneNumber) |
Obtains the dual-tone multifrequency (DTMF) control bit, pause character, and wait character
from a phone number.
|
static String |
formatPhoneNumber(String phoneNumber) |
Formats a phone number according to the Chinese Telephone Code Plan.
|
static String |
formatPhoneNumber(String phoneNumber,
String defaultCountryCode) |
Formats a phone number.
|
static String |
formatPhoneNumber(String phoneNumber,
String phoneNumberE164,
String defaultCountryCode) |
Formats a phone number according to the country code.
|
static String |
formatPhoneNumberToE164(String phoneNumber,
String defaultCountryCode) |
Formats a phone number into an E.164 representation.
|
static String |
getCountryIsoFromDbNumber(String phoneNumber) |
Obtains the ISO country code of a phone number from the database.
|
static int |
getIntlPrefixAndCCLen(String phoneNumber) |
Obtains the prefix length of a specified phone number.
|
static boolean |
isDialableDtmfKey(char input) |
Checks whether an input character is one of the 12 dialable DTMF keys on the dialer,
which are digits 0-9, the star key (*), and the pound key (#).
|
static boolean |
isDialableKey(char input) |
Checks whether an input character is dialable, that is, a digit ranging from 0 to 9,
the star key (*), the pound key (#), the plus sign (+), or WILD.
|
static boolean |
isDialTwelveKey(char input) |
已过时。
|
static boolean |
isEmergencyPhoneNumber(String phoneNumber) |
Checks whether a phone number is on the emergency number list.
|
static boolean |
isInternationalPhoneNumber(String phoneNumber) |
Checks whether a phone number is in the international number format.
|
static boolean |
isLatinDigit(char input) |
Checks whether an input character is a latin digit ranging from 0 to 9.
|
static boolean |
isLocalEmergencyPhoneNumber(String phoneNumber) |
Checks whether a phone number is an emergency number of the country where the calling party is located.
|
static boolean |
isNotSeparator(char input) |
Checks whether an input character is a non-separator.
|
static boolean |
isReallyDialableKey(char input) |
Checks whether an input character is a digit ranging from 0 to 9, the star key (*),
the pound key (#), or the plus sign (+).
|
static boolean |
isSuitableSmsAddress(String address) |
Checks whether the network address of the Short Message Service (SMS) can be used as the destination address.
|
static boolean |
isUriPhoneNumber(String phoneNumber) |
Checks whether a phone number contains '@' or '%40' to determine whether the phone number is a URI.
|
static boolean |
isVoiceMailNumber(String phoneNumber,
int slotId) |
Checks whether a phone number is on the voice mailbox number list provided by the SIM card.
|
static boolean |
isWaitOrPauseChar(char c) |
Checks whether a character is a wait or pause character.
|
static String |
normalizePhoneNumber(String phoneNumber) |
Normalizes a phone number by deleting characters other than digits.
|
static String |
removeSeparators(String phoneNumber) |
Removes separators from a phone number.
|
static String |
replacePauseAndWaitChar(String phoneNumber) |
Replaces pause characters with semicolons and waiting characters with commas in a specified phone number.
|
public static final int BCD_EXT_TYPE_CALLED_PARTY
public static final int BCD_EXT_TYPE_EF_ADN
public static final int INTERNATIONAL_TON_VALUE
public static final char PAUSE
public static final int UNKNOWN_TON_VALUE
public static final char WAIT
public static final char WILD
@Deprecated public static boolean isDialTwelveKey(char input)
input - Indicates the character to check.true if the character is one of the 12 characters on the dialer;
returns false otherwise.public static boolean isDialableDtmfKey(char input)
input - Indicates the character to check.true if the character is one of the 12 dialable DTMF keys on the dialer;
returns false otherwise.public static boolean isDialableKey(char input)
input - Indicates the character to check.true if the character is one of the characters listed;
returns false otherwise.public static boolean isUriPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to check.true if the phone number contains '@' or '%40'; returns false otherwise.public static boolean isInternationalPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to check.true if the phone number is in the international number format;
returns false otherwise.public static boolean isLatinDigit(char input)
input - Indicates the character to check.true if the character is a latin digit; returns false otherwise.public static boolean isNotSeparator(char input)
input - Indicates the character to check.true if the character is a non-separator; returns false otherwise.public static boolean isReallyDialableKey(char input)
input - Indicates the character to check.true if the character is one of the listed characters;
returns false otherwise.public static String convertCalledPartyBCDToStringWithTOA(byte[] data, int offset, int calledPartyBCDNumberLength, int bcdExtendedType)
data - Indicates the called party BCD number to convert.offset - Indicates the start position of the TOA field in the called party BCD number.calledPartyBCDNumberLength - Indicates the length of the called party BCD number.bcdExtendedType - Indicates the extended type of the called party BCD number.public static String convertCalledPartyBCDToStringWithoutTOA(byte[] data, int offset, int calledPartyBCDNumberLength, int bcdExtendedType)
data - Indicates the called party BCD number to convert.offset - Indicates the start position of the called party BCD number.calledPartyBCDNumberLength - Indicates the length of the called party BCD number.bcdExtendedType - Indicates the extended type of the called party BCD number.public static boolean isEmergencyPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to check.true if the phone number is on the emergency number list;
returns false otherwise.public static boolean isLocalEmergencyPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to check.true if the phone number is an emergency number of the country where the
calling party is located; returns false otherwise.public static String formatPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to format.public static String formatPhoneNumber(String phoneNumber, String defaultCountryCode)
If a phone number does not contain the country or region code, the system formats the phone number according to the transferred country or region code.
phoneNumber - Indicates the phone number to format.defaultCountryCode - Indicates a two-digit country code defined in ISO 3166-1.public static String formatPhoneNumber(String phoneNumber, String phoneNumberE164, String defaultCountryCode)
All the characters in a phone number must be dialable.
phoneNumber - Indicates the phone number to format.phoneNumberE164 - Indicates an E.164 number. If the phone number does not contain a country code,
the system formats the phone number according to phoneNumberE164.defaultCountryCode - Indicates a two-digit country code defined in ISO 3166-1. If phoneNumberE164
is null or invalid, or if the phone number is used for a call using international direct dialing (IDD),
the system formats the phone number according to defaultCountryCode.public static String formatPhoneNumberToE164(String phoneNumber, String defaultCountryCode)
phoneNumber - Indicates the phone number to format.defaultCountryCode - Indicates a two-digit country code defined in ISO 3166-1.public static boolean isVoiceMailNumber(String phoneNumber, int slotId)
Applications must have the ohos.permission.GET_TELEPHONY_STATE permission to call this method.
phoneNumber - Indicates the phone number to check.slotId - Indicates the ID of a SIM card slot.true if the phone number is on the voice mailbox number list;
returns false otherwise.public static String removeSeparators(String phoneNumber)
phoneNumber - Indicates the phone number for which the separators are to be removed.public static boolean isSuitableSmsAddress(String address)
address - Indicates the SMS address to check.true if the SMS address can be used as the destination address;
returns false otherwise.public static String normalizePhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to normalize.public static boolean comparePhoneNumbers(String phoneNumberA, String phoneNumberB)
This method uses loose comparison, which compares only digits and international prefixes or non-Russian trunk prefixes from right to left to see whether the two phone numbers are identical.
phoneNumberA - Indicates the first phone number.phoneNumberB - Indicates the second phone number.true if the two phone numbers are identical; returns false otherwise.public static String changeKeypadLettersToDigits(String data)
data - Indicates a phone number that may contain letters, for example, 1-887-ADqV-211.1-887-2378-211.public static String extractNetworkAddressPortion(String phoneNumber)
phoneNumber - Indicates the phone number to extract.public static String extractNetworkAddressPortionPlus(String phoneNumber)
phoneNumber - Indicates the phone number to process.null or a zero-length string.public static String extractPostDialPortion(String phoneNumber)
phoneNumber - Indicates the phone number to process.null or a zero-length string.public static String convertPhoneNumber(String phoneNumber)
phoneNumber - Indicates the phone number to process.null or a zero-length string.public static String getCountryIsoFromDbNumber(String phoneNumber)
phoneNumber - Indicates the phone number to query.public static int getIntlPrefixAndCCLen(String phoneNumber)
phoneNumber - Indicates the specified phone number.public static String replacePauseAndWaitChar(String phoneNumber)
phoneNumber - Indicates the phone number holding the characters to replace.public static boolean isWaitOrPauseChar(char c)
c - Indicates the character to check.true if the character is a wait or pause character; returns false otherwise.