PhoneNumberUtils
open class PhoneNumberUtils
kotlin.Any | |
↳ | android.telephony.PhoneNumberUtils |
Various utilities for dealing with phone number strings.
Summary
Constants | |
---|---|
static Int | |
static Int | |
static Int |
Japanese formatting |
static Int |
NANP formatting |
static Int |
The current locale is unknown, look for a country code or don't format |
static Char | |
static Int | |
static Int | |
static Char | |
static Char |
Public constructors | |
---|---|
Public methods | |
---|---|
open static Unit |
addTtsSpan(s: Spannable!, start: Int, endExclusive: Int) Attach a |
open static Boolean |
areSamePhoneNumber(number1: String, number2: String, defaultCountryIso: String) Determines if two phone numbers are the same. |
open static String! |
calledPartyBCDFragmentToString(bytes: ByteArray!, offset: Int, length: Int) Like calledPartyBCDToString, but field does not start with a TOA byte. |
open static String! |
calledPartyBCDFragmentToString(bytes: ByteArray!, offset: Int, length: Int, bcdExtType: Int) Like calledPartyBCDToString, but field does not start with a TOA byte. |
open static String! |
calledPartyBCDToString(bytes: ByteArray!, offset: Int, length: Int) 3GPP TS 24. |
open static String! |
calledPartyBCDToString(bytes: ByteArray!, offset: Int, length: Int, bcdExtType: Int) 3GPP TS 24. |
open static Boolean |
Compare phone numbers a and b, and return true if they're identical enough for caller ID purposes. |
open static Boolean |
Compare phone numbers a and b, return true if they're identical enough for caller ID purposes. |
open static String! |
convertKeypadLettersToDigits(input: String!) Translates any alphabetic letters (i.e. [A-Za-z]) in the specified phone number into the equivalent numeric digits, according to the phone keypad letter mapping described in ITU E. |
open static TtsSpan! |
createTtsSpan(phoneNumberString: String!) Create a |
open static CharSequence! |
createTtsSpannable(phoneNumber: CharSequence!) Wrap the supplied |
open static String! |
extractNetworkPortion(phoneNumber: String!) Extracts the network address portion and canonicalizes (filters out separators.) Network address portion is everything up to DTMF control digit separators (pause or wait), but without non-dialable characters. |
open static String! |
extractPostDialPortion(phoneNumber: String!) Extracts the post-dial sequence of DTMF control digits, pauses, and waits. |
open static Unit |
formatJapaneseNumber(text: Editable!) Formats a phone number in-place using the Japanese formatting rules. |
open static Unit |
formatNanpNumber(text: Editable!) Formats a phone number in-place using the NANP formatting rules. |
open static Unit |
formatNumber(text: Editable!, defaultFormattingType: Int) Formats a phone number in-place. |
open static String! |
formatNumber(source: String!) Breaks the given number down and formats it according to the rules for the country the number is from. |
open static String! |
formatNumber(phoneNumber: String!, defaultCountryIso: String!) Format a phone number. |
open static String! |
formatNumber(phoneNumber: String!, phoneNumberE164: String!, defaultCountryIso: String!) Format the phone number only if the given number hasn't been formatted. |
open static String! |
formatNumberToE164(phoneNumber: String!, defaultCountryIso: String!) Formats the specified |
open static String! |
formatNumberToRFC3966(phoneNumber: String!, defaultCountryIso: String!) Formats the specified |
open static Int |
getFormatTypeForLocale(locale: Locale!) Returns the phone number formatting type for the given locale. |
open static String! |
getNumberFromIntent(intent: Intent!, context: Context!) Extracts the phone number from an Intent. |
open static String! |
getStrippedReversed(phoneNumber: String!) Returns the network portion reversed. |
static Boolean |
True if c is ISO-LATIN characters 0-9, *, # |
static Boolean |
isDialable(c: Char) True if c is ISO-LATIN characters 0-9, *, # , +, WILD |
open static Boolean |
isEmergencyNumber(number: String!) Checks a given number against the list of emergency numbers provided by the RIL and SIM card. |
open static Boolean |
isGlobalPhoneNumber(phoneNumber: String!) |
open static Boolean |
isISODigit(c: Char) True if c is ISO-LATIN characters 0-9 |
open static Boolean |
isLocalEmergencyNumber(context: Context!, number: String!) Checks if a given number is an emergency number for the country that the user is in. |
static Boolean |
isNonSeparator(c: Char) True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE |
static Boolean |
isReallyDialable(c: Char) True if c is ISO-LATIN characters 0-9, *, # , + (no WILD) |
static Boolean |
isStartsPostDial(c: Char) This any anything to the right of this char is part of the post-dial string (eg this is PAUSE or WAIT) |
open static Boolean |
isVoiceMailNumber(number: String!) isVoiceMailNumber: checks a given number against the voicemail number provided by the RIL and SIM card. |
open static Boolean |
isWellFormedSmsAddress(address: String!) Return true iff the network portion of |
open static Boolean |
isWpsCallNumber(number: String) Check if the number is for Wireless Priority Service call. |
open static ByteArray! |
Note: calls extractNetworkPortion(), so do not use for SIM EF[ADN] style records Returns null if network portion is empty. |
open static ByteArray! |
Same as |
open static String! |
normalizeNumber(phoneNumber: String!) Normalize a phone number by removing the characters other than digits. |
open static ByteArray! |
numberToCalledPartyBCD(number: String!) Convert a dialing number to BCD byte array |
open static ByteArray! |
numberToCalledPartyBCD(number: String!, bcdExtType: Int) Convert a dialing number to BCD byte array |
open static String! |
replaceUnicodeDigits(number: String!) Replaces all unicode(e.g. Arabic, Persian) digits with their decimal digit equivalents. |
open static String! |
stringFromStringAndTOA(s: String!, TOA: Int) Basically: makes sure there's a + in front of a TOA_International number Returns null if s == null |
open static String! |
stripSeparators(phoneNumber: String!) Strips separators from a phone number string. |
open static String! |
toCallerIDMinMatch(phoneNumber: String!) Returns the rightmost minimum matched characters in the network portion in *reversed* order This can be used to do a database lookup against the column that stores getStrippedReversed() Returns null if phoneNumber == null |
open static Int |
toaFromString(s: String!) Returns the TOA for the given dial string Basically, returns TOA_International if there's a + prefix |
Constants
BCD_EXTENDED_TYPE_CALLED_PARTY
static val BCD_EXTENDED_TYPE_CALLED_PARTY: Int
Value: 2
FORMAT_UNKNOWN
static val FORMAT_UNKNOWN: Int
The current locale is unknown, look for a country code or don't format
Value: 0
Public constructors
PhoneNumberUtils
PhoneNumberUtils()
Public methods
addTtsSpan
open static fun addTtsSpan(
s: Spannable!,
start: Int,
endExclusive: Int
): Unit
Attach a TtsSpan
to the supplied Spannable
at the indicated location, annotating that location as containing a phone number.
Parameters | |
---|---|
s |
Spannable!: A Spannable to annotate. |
start |
Int: The starting character position of the phone number in s . |
endExclusive |
Int: The position after the ending character in the phone number s . |
areSamePhoneNumber
open static fun areSamePhoneNumber(
number1: String,
number2: String,
defaultCountryIso: String
): Boolean
Determines if two phone numbers are the same.
Matching is based on compare(java.lang.String,java.lang.String), matching takes into account national dialing plans rather than simply matching the last 7 digits of the two phone numbers. As a result, it is expected that some numbers which would match using the previous method will no longer match using this new approach.
Parameters | |
---|---|
number1 |
String: This value cannot be null . |
number2 |
String: This value cannot be null . |
defaultCountryIso |
String: The lowercase two letter ISO 3166-1 country code. Used when parsing the phone numbers where it is not possible to determine the country associated with a phone number based on the number alone. It is recommended to pass in TelephonyManager.getNetworkCountryIso() . This value cannot be null . |
Return | |
---|---|
Boolean |
True if the two given phone number are same. |
calledPartyBCDFragmentToString
open static funcalledPartyBCDFragmentToString(
bytes: ByteArray!,
offset: Int,
length: Int
): String!
Deprecated: use calledPartyBCDFragmentToString(byte[],int,int,int)
instead. Calling this method is equivalent to calling calledPartyBCDFragmentToString(byte[],int,int,int)
with BCD_EXTENDED_TYPE_EF_ADN
as the extended type.
Like calledPartyBCDToString, but field does not start with a TOA byte. For example: SIM ADN extension fields
calledPartyBCDFragmentToString
open static fun calledPartyBCDFragmentToString(
bytes: ByteArray!,
offset: Int,
length: Int,
bcdExtType: Int
): String!
Like calledPartyBCDToString, but field does not start with a TOA byte. For example: SIM ADN extension fields
Parameters | |
---|---|
bcdExtType |
Int: Value is android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_EF_ADN , or android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_CALLED_PARTY |
calledPartyBCDToString
open static funcalledPartyBCDToString(
bytes: ByteArray!,
offset: Int,
length: Int
): String!
Deprecated: use calledPartyBCDToString(byte[],int,int,int)
instead. Calling this method is equivalent to calling calledPartyBCDToString(byte[],int,int)
with BCD_EXTENDED_TYPE_EF_ADN
as the extended type.
3GPP TS 24.008 10.5.4.7 Called Party BCD Number See Also TS 51.011 10.5.1 "dialing number/ssc string" and TS 11.11 "10.3.1 EF adn (Abbreviated dialing numbers)"
Parameters | |
---|---|
bytes |
ByteArray!: the data buffer |
offset |
Int: should point to the TOA (aka. TON/NPI) octet after the length byte |
length |
Int: is the number of bytes including TOA byte and must be at least 2 |
Return | |
---|---|
String! |
partial string on invalid decode |
calledPartyBCDToString
open static fun calledPartyBCDToString(
bytes: ByteArray!,
offset: Int,
length: Int,
bcdExtType: Int
): String!
3GPP TS 24.008 10.5.4.7 Called Party BCD Number See Also TS 51.011 10.5.1 "dialing number/ssc string" and TS 11.11 "10.3.1 EF adn (Abbreviated dialing numbers)"
Parameters | |
---|---|
bytes |
ByteArray!: the data buffer |
offset |
Int: should point to the TOA (aka. TON/NPI) octet after the length byte |
length |
Int: is the number of bytes including TOA byte and must be at least 2 |
bcdExtType |
Int: used to determine the extended bcd coding Value is android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_EF_ADN , or android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_CALLED_PARTY |
compare
open static funcompare(
context: Context!,
a: String!,
b: String!
): Boolean
Deprecated: use areSamePhoneNumber(java.lang.String,java.lang.String,java.lang.String)
instead
Compare phone numbers a and b, and return true if they're identical enough for caller ID purposes. Checks a resource to determine whether to use a strict or loose comparison algorithm.
compare
open static funcompare(
a: String!,
b: String!
): Boolean
Deprecated: use areSamePhoneNumber(java.lang.String,java.lang.String,java.lang.String)
instead
Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.
convertKeypadLettersToDigits
open static fun convertKeypadLettersToDigits(input: String!): String!
Translates any alphabetic letters (i.e. [A-Za-z]) in the specified phone number into the equivalent numeric digits, according to the phone keypad letter mapping described in ITU E.161 and ISO/IEC 9995-8.
Return | |
---|---|
String! |
the input string, with alpha letters converted to numeric digits using the phone keypad letter mapping. For example, an input of "1-800-GOOG-411" will return "1-800-4664-411". |
createTtsSpan
open static fun createTtsSpan(phoneNumberString: String!): TtsSpan!
Create a TtsSpan
for the supplied String
.
Parameters | |
---|---|
phoneNumberString |
String!: A String the entirety of which represents a phone number. |
Return | |
---|---|
TtsSpan! |
A TtsSpan for {@param phoneNumberString}. |
createTtsSpannable
open static fun createTtsSpannable(phoneNumber: CharSequence!): CharSequence!
Wrap the supplied CharSequence
with a TtsSpan
, annotating it as containing a phone number in its entirety.
Parameters | |
---|---|
phoneNumber |
CharSequence!: A CharSequence the entirety of which represents a phone number. |
Return | |
---|---|
CharSequence! |
A CharSequence with appropriate annotations. |
extractNetworkPortion
open static fun extractNetworkPortion(phoneNumber: String!): String!
Extracts the network address portion and canonicalizes (filters out separators.) Network address portion is everything up to DTMF control digit separators (pause or wait), but without non-dialable characters. Please note that the GSM wild character is allowed in the result. This must be resolved before dialing. Returns null if phoneNumber == null
extractPostDialPortion
open static fun extractPostDialPortion(phoneNumber: String!): String!
Extracts the post-dial sequence of DTMF control digits, pauses, and waits. Strips separators. This string may be empty, but will not be null unless phoneNumber == null. Returns null if phoneNumber == null
formatJapaneseNumber
open static funformatJapaneseNumber(text: Editable!): Unit
Deprecated: Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
Formats a phone number in-place using the Japanese formatting rules. Numbers will be formatted as:
03-xxxx-xxxx 090-xxxx-xxxx 0120-xxx-xxx +81-3-xxxx-xxxx +81-90-xxxx-xxxx
Parameters | |
---|---|
text |
Editable!: the number to be formatted, will be modified with the formatting |
formatNanpNumber
open static funformatNanpNumber(text: Editable!): Unit
Deprecated: Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
Formats a phone number in-place using the NANP formatting rules. Numbers will be formatted as:
xxxxx xxx-xxxx xxx-xxx-xxxx 1-xxx-xxx-xxxx +1-xxx-xxx-xxxx
Parameters | |
---|---|
text |
Editable!: the number to be formatted, will be modified with the formatting |
formatNumber
open static funformatNumber(
text: Editable!,
defaultFormattingType: Int
): Unit
Deprecated: Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
Formats a phone number in-place. Currently FORMAT_JAPAN
and FORMAT_NANP
is supported as a second argument.
Parameters | |
---|---|
text |
Editable!: The number to be formatted, will be modified with the formatting |
defaultFormattingType |
Int: The default formatting rules to apply if the number does not begin with +[country_code] |
formatNumber
open static funformatNumber(source: String!): String!
Deprecated: Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
Breaks the given number down and formats it according to the rules for the country the number is from.
Parameters | |
---|---|
source |
String!: The phone number to format |
Return | |
---|---|
String! |
A locally acceptable formatting of the input, or the raw input if formatting rules aren't known for the number |
formatNumber
open static fun formatNumber(
phoneNumber: String!,
defaultCountryIso: String!
): String!
Format a phone number.
If the given number doesn't have the country code, the phone will be formatted to the default country's convention.
Parameters | |
---|---|
phoneNumber |
String!: the number to be formatted. |
defaultCountryIso |
String!: the ISO 3166-1 two letters country code whose convention will be used if the given number doesn't have the country code. |
Return | |
---|---|
String! |
the formatted number, or null if the given number is not valid. |
formatNumber
open static fun formatNumber(
phoneNumber: String!,
phoneNumberE164: String!,
defaultCountryIso: String!
): String!
Format the phone number only if the given number hasn't been formatted.
The number which has only dailable character is treated as not being formatted.
Parameters | |
---|---|
phoneNumber |
String!: the number to be formatted. |
phoneNumberE164 |
String!: the E164 format number whose country code is used if the given phoneNumber doesn't have the country code. |
defaultCountryIso |
String!: the ISO 3166-1 two letters country code whose convention will be used if the phoneNumberE164 is null or invalid, or if phoneNumber contains IDD. |
Return | |
---|---|
String! |
the formatted number if the given number has been formatted, otherwise, return the given number. |
formatNumberToE164
open static fun formatNumberToE164(
phoneNumber: String!,
defaultCountryIso: String!
): String!
Formats the specified phoneNumber
to the E.164 representation.
Parameters | |
---|---|
phoneNumber |
String!: the phone number to format. |
defaultCountryIso |
String!: the ISO 3166-1 two letters country code in UPPER CASE. |
Return | |
---|---|
String! |
the E.164 representation, or null if the given phone number is not valid. |
formatNumberToRFC3966
open static fun formatNumberToRFC3966(
phoneNumber: String!,
defaultCountryIso: String!
): String!
Formats the specified phoneNumber
to the RFC3966 representation.
Parameters | |
---|---|
phoneNumber |
String!: the phone number to format. |
defaultCountryIso |
String!: the ISO 3166-1 two letters country code in UPPER CASE. |
Return | |
---|---|
String! |
the RFC3966 representation, or null if the given phone number is not valid. |
getFormatTypeForLocale
open static fungetFormatTypeForLocale(locale: Locale!): Int
Deprecated: Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
Returns the phone number formatting type for the given locale.
Parameters | |
---|---|
locale |
Locale!: The locale of interest, usually Locale.getDefault() |
Return | |
---|---|
Int |
The formatting type for the given locale, or FORMAT_UNKNOWN if the formatting rules are not known for the given locale |
getNumberFromIntent
open static fun getNumberFromIntent(
intent: Intent!,
context: Context!
): String!
Extracts the phone number from an Intent.
Parameters | |
---|---|
intent |
Intent!: the intent to get the number of |
context |
Context!: a context to use for database access |
Return | |
---|---|
String! |
the phone number that would be called by the intent, or null if the number cannot be found. |
getStrippedReversed
open static fun getStrippedReversed(phoneNumber: String!): String!
Returns the network portion reversed. This string is intended to go into an index column for a database lookup. Returns null if phoneNumber == null
is12Key
static fun is12Key(c: Char): Boolean
True if c is ISO-LATIN characters 0-9, *, #
isDialable
static fun isDialable(c: Char): Boolean
True if c is ISO-LATIN characters 0-9, *, # , +, WILD
isEmergencyNumber
open static funisEmergencyNumber(number: String!): Boolean
Deprecated: Please use TelephonyManager.isEmergencyNumber(String)
instead.
Checks a given number against the list of emergency numbers provided by the RIL and SIM card.
Parameters | |
---|---|
number |
String!: the number to look up. |
Return | |
---|---|
Boolean |
true if the number is in the list of emergency numbers listed in the RIL / SIM, otherwise return false. |
isGlobalPhoneNumber
open static fun isGlobalPhoneNumber(phoneNumber: String!): Boolean
isISODigit
open static fun isISODigit(c: Char): Boolean
True if c is ISO-LATIN characters 0-9
isLocalEmergencyNumber
open static funisLocalEmergencyNumber(
context: Context!,
number: String!
): Boolean
Deprecated: Please use TelephonyManager.isEmergencyNumber(String)
instead.
Checks if a given number is an emergency number for the country that the user is in.
Parameters | |
---|---|
number |
String!: the number to look up. |
context |
Context!: the specific context which the number should be checked against |
Return | |
---|---|
Boolean |
true if the specified number is an emergency number for the country the user is currently in. |
isNonSeparator
static fun isNonSeparator(c: Char): Boolean
True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE
isReallyDialable
static fun isReallyDialable(c: Char): Boolean
True if c is ISO-LATIN characters 0-9, *, # , + (no WILD)
isStartsPostDial
static fun isStartsPostDial(c: Char): Boolean
This any anything to the right of this char is part of the post-dial string (eg this is PAUSE or WAIT)
isVoiceMailNumber
open static fun isVoiceMailNumber(number: String!): Boolean
isVoiceMailNumber: checks a given number against the voicemail number provided by the RIL and SIM card. The caller must have the READ_PHONE_STATE credential.
Parameters | |
---|---|
number |
String!: the number to look up. |
Return | |
---|---|
Boolean |
true if the number is in the list of voicemail. False otherwise, including if the caller does not have the permission to read the VM number. |
isWellFormedSmsAddress
open static fun isWellFormedSmsAddress(address: String!): Boolean
Return true iff the network portion of address
is, as far as we can tell on the device, suitable for use as an SMS destination address.
isWpsCallNumber
open static fun isWpsCallNumber(number: String): Boolean
Check if the number is for Wireless Priority Service call.
Parameters | |
---|---|
number |
String: The phone number used for WPS call. This value cannot be null . |
Return | |
---|---|
Boolean |
true if number matches WPS pattern and false otherwise. |
networkPortionToCalledPartyBCD
open static fun networkPortionToCalledPartyBCD(s: String!): ByteArray!
Note: calls extractNetworkPortion(), so do not use for SIM EF[ADN] style records Returns null if network portion is empty.
networkPortionToCalledPartyBCDWithLength
open static fun networkPortionToCalledPartyBCDWithLength(s: String!): ByteArray!
Same as networkPortionToCalledPartyBCD
, but includes a one-byte length prefix.
normalizeNumber
open static fun normalizeNumber(phoneNumber: String!): String!
Normalize a phone number by removing the characters other than digits. If the given number has keypad letters, the letters will be converted to digits first.
Parameters | |
---|---|
phoneNumber |
String!: the number to be normalized. |
Return | |
---|---|
String! |
the normalized number. |
numberToCalledPartyBCD
open static funnumberToCalledPartyBCD(number: String!): ByteArray!
Deprecated: use numberToCalledPartyBCD(java.lang.String,int)
instead. Calling this method is equivalent to calling numberToCalledPartyBCD(java.lang.String,int)
with BCD_EXTENDED_TYPE_EF_ADN
as the extended type.
Convert a dialing number to BCD byte array
Parameters | |
---|---|
number |
String!: dialing number string. If the dialing number starts with '+', set to international TOA |
Return | |
---|---|
ByteArray! |
BCD byte array |
numberToCalledPartyBCD
open static fun numberToCalledPartyBCD(
number: String!,
bcdExtType: Int
): ByteArray!
Convert a dialing number to BCD byte array
Parameters | |
---|---|
number |
String!: dialing number string. If the dialing number starts with '+', set to international TOA |
bcdExtType |
Int: used to determine the extended bcd coding Value is android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_EF_ADN , or android.telephony.PhoneNumberUtils#BCD_EXTENDED_TYPE_CALLED_PARTY |
Return | |
---|---|
ByteArray! |
BCD byte array |
replaceUnicodeDigits
open static fun replaceUnicodeDigits(number: String!): String!
Replaces all unicode(e.g. Arabic, Persian) digits with their decimal digit equivalents.
Parameters | |
---|---|
number |
String!: the number to perform the replacement on. |
Return | |
---|---|
String! |
the replaced number. |
stringFromStringAndTOA
open static fun stringFromStringAndTOA(
s: String!,
TOA: Int
): String!
Basically: makes sure there's a + in front of a TOA_International number Returns null if s == null
stripSeparators
open static fun stripSeparators(phoneNumber: String!): String!
Strips separators from a phone number string.
Parameters | |
---|---|
phoneNumber |
String!: phone number to strip. |
Return | |
---|---|
String! |
phone string stripped of separators. |
toCallerIDMinMatch
open static fun toCallerIDMinMatch(phoneNumber: String!): String!
Returns the rightmost minimum matched characters in the network portion in *reversed* order This can be used to do a database lookup against the column that stores getStrippedReversed() Returns null if phoneNumber == null
toaFromString
open static fun toaFromString(s: String!): Int
Returns the TOA for the given dial string Basically, returns TOA_International if there's a + prefix