public class PhoneNumberUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
FORMAT_JAPAN
Japanese formatting
|
static int |
FORMAT_NANP
NANP formatting
|
static int |
FORMAT_UNKNOWN
The current locale is unknown, look for a country code or don't format
|
static char |
PAUSE |
static int |
TOA_International |
static int |
TOA_Unknown |
static char |
WAIT |
static char |
WILD |
Constructor and Description |
---|
PhoneNumberUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
calledPartyBCDFragmentToString(byte[] bytes,
int offset,
int length)
Like calledPartyBCDToString, but field does not start with a
TOA byte.
|
static String |
calledPartyBCDToString(byte[] bytes,
int offset,
int length)
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)"
|
static String |
cdmaCheckAndProcessPlusCode(String dialStr)
This function checks if there is a plus sign (+) in the passed-in dialing number.
|
static String |
cdmaCheckAndProcessPlusCodeByNumberFormat(String dialStr,
int currFormat,
int defaultFormat)
This function should be called from checkAndProcessPlusCode only
And it is used for test purpose also.
|
static boolean |
compare(Context context,
String a,
String b)
Compare phone numbers a and b, and return true if they're identical
enough for caller ID purposes.
|
static boolean |
compare(String a,
String b)
Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.
|
static boolean |
compare(String a,
String b,
boolean useStrictComparation) |
static boolean |
compareLoosely(String a,
String b)
Compare phone numbers a and b, return true if they're identical
enough for caller ID purposes.
|
static boolean |
compareStrictly(String a,
String b) |
static boolean |
compareStrictly(String a,
String b,
boolean acceptInvalidCCCPrefix) |
static String |
convertAndStrip(String phoneNumber)
Translates keypad letters to actual digits (e.g.
|
static String |
convertKeypadLettersToDigits(String input)
Translates any alphabetic letters (i.e.
|
static String |
convertPreDial(String phoneNumber)
Converts pause and tonewait pause characters
to Android representation.
|
static String |
extractNetworkPortion(String phoneNumber)
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.
|
static String |
extractNetworkPortionAlt(String phoneNumber)
Extracts the network address portion and canonicalize.
|
static String |
extractPostDialPortion(String phoneNumber)
Extracts the post-dial sequence of DTMF control digits, pauses, and
waits.
|
static void |
formatJapaneseNumber(Editable text)
Formats a phone number in-place using the Japanese formatting rules.
|
static void |
formatNanpNumber(Editable text)
Formats a phone number in-place using the NANP formatting rules.
|
static void |
formatNumber(Editable text,
int defaultFormattingType)
Formats a phone number in-place.
|
static String |
formatNumber(String source)
Breaks the given number down and formats it according to the rules
for the country the number is from.
|
static String |
formatNumber(String source,
int defaultFormattingType)
Formats the given number with the given formatting type.
|
static String |
formatNumber(String phoneNumber,
String defaultCountryIso)
Format a phone number.
|
static String |
formatNumber(String phoneNumber,
String phoneNumberE164,
String defaultCountryIso)
Format the phone number only if the given number hasn't been formatted.
|
static String |
formatNumberToE164(String phoneNumber,
String defaultCountryIso)
Format the given phoneNumber to the E.164 representation.
|
static int |
getFormatTypeForLocale(Locale locale)
Returns the phone number formatting type for the given locale.
|
static String |
getNumberFromIntent(Intent intent,
Context context)
Extracts the phone number from an Intent.
|
static String |
getStrippedReversed(String phoneNumber)
Returns the network portion reversed.
|
static String |
getUsernameFromUriNumber(String number) |
static boolean |
is12Key(char c)
True if c is ISO-LATIN characters 0-9, *, #
|
static boolean |
isDialable(char c)
True if c is ISO-LATIN characters 0-9, *, # , +, WILD
|
static boolean |
isEmergencyNumber(String number)
Checks a given number against the list of
emergency numbers provided by the RIL and SIM card.
|
static boolean |
isEmergencyNumber(String number,
String defaultCountryIso)
Checks if a given number is an emergency number for a specific country.
|
static boolean |
isGlobalPhoneNumber(String phoneNumber) |
static boolean |
isISODigit(char c)
True if c is ISO-LATIN characters 0-9
|
static boolean |
isLocalEmergencyNumber(String number,
Context context)
Checks if a given number is an emergency number for the country that the user is in.
|
static boolean |
isNonSeparator(char c)
True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE
|
static boolean |
isPotentialEmergencyNumber(String number)
Checks if given number might *potentially* result in
a call to an emergency service on the current network.
|
static boolean |
isPotentialEmergencyNumber(String number,
String defaultCountryIso)
Checks if a given number might *potentially* result in a call to an
emergency service, for a specific country.
|
static boolean |
isPotentialLocalEmergencyNumber(String number,
Context context)
Checks if a given number might *potentially* result in a call to an
emergency service, for the country that the user is in.
|
static boolean |
isReallyDialable(char c)
True if c is ISO-LATIN characters 0-9, *, # , + (no WILD)
|
static boolean |
isStartsPostDial(char c)
This any anything to the right of this char is part of the
post-dial string (eg this is PAUSE or WAIT)
|
static boolean |
isUriNumber(String number)
Determines if the specified number is actually a URI
(i.e.
|
static boolean |
isVoiceMailNumber(String number)
isVoiceMailNumber: checks a given number against the voicemail
number provided by the RIL and SIM card.
|
static boolean |
isWellFormedSmsAddress(String address)
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. |
static byte[] |
networkPortionToCalledPartyBCD(String s)
Note: calls extractNetworkPortion(), so do not use for
SIM EF[ADN] style records
Returns null if network portion is empty.
|
static byte[] |
networkPortionToCalledPartyBCDWithLength(String s)
Same as
networkPortionToCalledPartyBCD(java.lang.String) , but includes a
one-byte length prefix. |
static String |
normalizeNumber(String phoneNumber)
Normalize a phone number by removing the characters other than digits.
|
static byte[] |
numberToCalledPartyBCD(String number)
Convert a dialing number to BCD byte array
|
static String |
replaceUnicodeDigits(String number)
Replace arabic/unicode digits with decimal digits.
|
static String |
stringFromStringAndTOA(String s,
int TOA)
Basically: makes sure there's a + in front of a
TOA_International number
Returns null if s == null
|
static String |
stripSeparators(String phoneNumber)
Strips separators from a phone number string.
|
static int |
toaFromString(String s)
Returns the TOA for the given dial string
Basically, returns TOA_International if there's a + prefix
|
static String |
toCallerIDMinMatch(String phoneNumber)
Returns the rightmost MIN_MATCH (5) 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
|
public static final char PAUSE
public static final char WAIT
public static final char WILD
public static final int TOA_International
public static final int TOA_Unknown
public static final int FORMAT_UNKNOWN
public static final int FORMAT_NANP
public static final int FORMAT_JAPAN
public static boolean isISODigit(char c)
public static final boolean is12Key(char c)
public static final boolean isDialable(char c)
public static final boolean isReallyDialable(char c)
public static final boolean isNonSeparator(char c)
public static final boolean isStartsPostDial(char c)
public static String getNumberFromIntent(Intent intent, Context context)
intent
- the intent to get the number ofcontext
- a context to use for database accessnull
if the number cannot be found.public static String extractNetworkPortion(String phoneNumber)
public static String extractNetworkPortionAlt(String phoneNumber)
public static String stripSeparators(String phoneNumber)
phoneNumber
- phone number to strip.public static String convertAndStrip(String phoneNumber)
public static String convertPreDial(String phoneNumber)
public static String extractPostDialPortion(String phoneNumber)
public static boolean compare(String a, String b)
public static boolean compare(Context context, String a, String b)
public static boolean compareLoosely(String a, String b)
public static boolean compareStrictly(String a, String b, boolean acceptInvalidCCCPrefix)
public static String toCallerIDMinMatch(String phoneNumber)
public static String getStrippedReversed(String phoneNumber)
public static String stringFromStringAndTOA(String s, int TOA)
public static int toaFromString(String s)
public static String calledPartyBCDToString(byte[] bytes, int offset, int length)
bytes
- the data bufferoffset
- should point to the TOA (aka. TON/NPI) octet after the length bytelength
- is the number of bytes including TOA byte
and must be at least 2public static String calledPartyBCDFragmentToString(byte[] bytes, int offset, int length)
public static boolean isWellFormedSmsAddress(String address)
address
is,
as far as we can tell on the device, suitable for use as an SMS
destination address.public static boolean isGlobalPhoneNumber(String phoneNumber)
public static byte[] networkPortionToCalledPartyBCD(String s)
public static byte[] networkPortionToCalledPartyBCDWithLength(String s)
networkPortionToCalledPartyBCD(java.lang.String)
, but includes a
one-byte length prefix.public static byte[] numberToCalledPartyBCD(String number)
number
- dialing number string
if the dialing number starts with '+', set to international TOApublic static String formatNumber(String source)
source
- The phone number to formatpublic static String formatNumber(String source, int defaultFormattingType)
FORMAT_NANP
and FORMAT_JAPAN
are supported as a formating type.source
- the phone number to formatdefaultFormattingType
- The default formatting rules to apply if the number does
not begin with +[country_code]public static int getFormatTypeForLocale(Locale locale)
locale
- The locale of interest, usually Locale.getDefault()
public static void formatNumber(Editable text, int defaultFormattingType)
FORMAT_JAPAN
and FORMAT_NANP
is supported as a second argument.text
- The number to be formatted, will be modified with the formattingdefaultFormattingType
- The default formatting rules to apply if the number does
not begin with +[country_code]public static void formatNanpNumber(Editable text)
xxxxx
xxx-xxxx
xxx-xxx-xxxx
1-xxx-xxx-xxxx
+1-xxx-xxx-xxxx
text
- the number to be formatted, will be modified with the formattingpublic static void formatJapaneseNumber(Editable text)
03-xxxx-xxxx
090-xxxx-xxxx
0120-xxx-xxx
+81-3-xxxx-xxxx
+81-90-xxxx-xxxx
text
- the number to be formatted, will be modified with
the formattingpublic static String formatNumberToE164(String phoneNumber, String defaultCountryIso)
The given phone number must have an area code and could have a country code.
The defaultCountryIso is used to validate the given number and generate the E.164 phone number if the given number doesn't have a country code.
phoneNumber
- the phone number to formatdefaultCountryIso
- the ISO 3166-1 two letters country codepublic static String formatNumber(String phoneNumber, String defaultCountryIso)
If the given number doesn't have the country code, the phone will be formatted to the default country's convention.
phoneNumber
- the number to be formatted.defaultCountryIso
- the ISO 3166-1 two letters country code whose convention will
be used if the given number doesn't have the country code.public static String formatNumber(String phoneNumber, String phoneNumberE164, String defaultCountryIso)
The number which has only dailable character is treated as not being formatted.
phoneNumber
- the number to be formatted.phoneNumberE164
- the E164 format number whose country code is used if the given
phoneNumber doesn't have the country code.defaultCountryIso
- 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.public static String normalizeNumber(String phoneNumber)
phoneNumber
- the number to be normalized.public static String replaceUnicodeDigits(String number)
number
- the number to be normalized.public static boolean isEmergencyNumber(String number)
number
- the number to look up.public static boolean isPotentialEmergencyNumber(String number)
number
- the number to look up.public static boolean isEmergencyNumber(String number, String defaultCountryIso)
number
- the number to look up.defaultCountryIso
- the specific country which the number should be checked againstpublic static boolean isPotentialEmergencyNumber(String number, String defaultCountryIso)
number
- the number to look up.defaultCountryIso
- the specific country which the number should be checked againstpublic static boolean isLocalEmergencyNumber(String number, Context context)
number
- the number to look up.context
- the specific context which the number should be checked againstCountryDetector
public static boolean isPotentialLocalEmergencyNumber(String number, Context context)
number
- the number to look up.context
- the specific context which the number should be checked againstCountryDetector
public static boolean isVoiceMailNumber(String number)
number
- the number to look up.public static String convertKeypadLettersToDigits(String input)
public static String cdmaCheckAndProcessPlusCode(String dialStr)
dialStr
- the original dial stringpublic static String cdmaCheckAndProcessPlusCodeByNumberFormat(String dialStr, int currFormat, int defaultFormat)
dialStr
- the original dial stringcurrFormat
- the numbering system of the current country that the phone is camped ondefaultFormat
- the numbering system of the country that the phone is activated onpublic static boolean isUriNumber(String number)
number
- public static String getUsernameFromUriNumber(String number)
number
- SIP address of the form "username@domainname"
(or the URI-escaped equivalent "username%40domainname")isUriNumber