Build 1.0_r1(from source)

android.telephony
Class PhoneNumberUtils

java.lang.Object
  extended by android.telephony.PhoneNumberUtils

public class PhoneNumberUtils
extends Object

Various utilities for dealing with phone number strings.


Field Summary
static int FORMAT_NANP
          NANP formatting
static int FORMAT_UNKNOWN
          The current locale is unknown, look for a country code or don't format
(package private) static int MIN_MATCH
           
static char PAUSE
           
static int TOA_International
           
static int TOA_Unknown
           
static char WAIT
           
static char WILD
           
 
Constructor Summary
PhoneNumberUtils()
           
 
Method Summary
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"
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 String convertKeypadLettersToDigits(String input)
          Translates any alphabetic letters (i.e.
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 extractPostDialPortion(String phoneNumber)
          Extracts the post-dial sequence of DTMF control digits, pauses, and waits.
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 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 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)
          isEmergencyNumber: checks a given number against the list of emergency numbers provided by the RIL and SIM card.
static boolean isGlobalPhoneNumber(String phoneNumber)
           
static boolean isISODigit(char c)
          True if c is ISO-LATIN characters 0-9
static boolean isNonSeparator(char c)
          True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE
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 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 Exceptions thrown if extractNetworkPortion(s).length() == 0
static byte[] networkPortionToCalledPartyBCDWithLength(String s)
          Same as networkPortionToCalledPartyBCD(java.lang.String), but includes a one-byte length prefix.
static byte[] numberToCalledPartyBCD(String number)
          Convert a dialing number to BCD byte array
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAUSE

public static final char PAUSE
See Also:
Constant Field Values

WAIT

public static final char WAIT
See Also:
Constant Field Values

WILD

public static final char WILD
See Also:
Constant Field Values

TOA_International

public static final int TOA_International
See Also:
Constant Field Values

TOA_Unknown

public static final int TOA_Unknown
See Also:
Constant Field Values

FORMAT_UNKNOWN

public static final int FORMAT_UNKNOWN
The current locale is unknown, look for a country code or don't format

See Also:
Constant Field Values

FORMAT_NANP

public static final int FORMAT_NANP
NANP formatting

See Also:
Constant Field Values

MIN_MATCH

static final int MIN_MATCH
See Also:
Constant Field Values
Constructor Detail

PhoneNumberUtils

public PhoneNumberUtils()
Method Detail

isISODigit

public static boolean isISODigit(char c)
True if c is ISO-LATIN characters 0-9


is12Key

public static final boolean is12Key(char c)
True if c is ISO-LATIN characters 0-9, *, #


isDialable

public static final boolean isDialable(char c)
True if c is ISO-LATIN characters 0-9, *, # , +, WILD


isReallyDialable

public static final boolean isReallyDialable(char c)
True if c is ISO-LATIN characters 0-9, *, # , + (no WILD)


isNonSeparator

public static final boolean isNonSeparator(char c)
True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE


isStartsPostDial

public static final 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)


getNumberFromIntent

public static String getNumberFromIntent(Intent intent,
                                         Context context)
Extracts the phone number from an Intent.

Parameters:
intent - the intent to get the number of
context - a context to use for database access
Returns:
the phone number that would be called by the intent, or null if the number cannot be found.

extractNetworkPortion

public 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. Please note that the GSM wild character is allowed in the result. This must be resolved before dialing. Allows + only in the first position in the result string. Returns null if phoneNumber == null


stripSeparators

public static String stripSeparators(String phoneNumber)
Strips separators from a phone number string.

Parameters:
phoneNumber - phone number to strip.
Returns:
phone string stripped of separators.

extractPostDialPortion

public static String extractPostDialPortion(String phoneNumber)
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


compare

public static boolean compare(String a,
                              String b)
Compare phone numbers a and b, return true if they're identical enough for caller ID purposes. - Compares from right to left - requires MIN_MATCH (5) characters to match - handles common trunk prefixes and international prefixes (basically, everything except the Russian trunk prefix) Tolerates nulls


toCallerIDMinMatch

public 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


getStrippedReversed

public static String getStrippedReversed(String phoneNumber)
Returns the network portion reversed. This string is intended to go into an index column for a database lookup. Returns null if phoneNumber == null


stringFromStringAndTOA

public 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


toaFromString

public static int toaFromString(String s)
Returns the TOA for the given dial string Basically, returns TOA_International if there's a + prefix


calledPartyBCDToString

public 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"

Parameters:
bytes - the data buffer
offset - should point to the TOI/NPI octet after the length byte
length - is the number of bytes including TOA byte and must be at least 2
Returns:
partial string on invalid decode FIXME(mkf) support alphanumeric address type currently implemented in SMSMessage.getAddress()

calledPartyBCDFragmentToString

public static String calledPartyBCDFragmentToString(byte[] bytes,
                                                    int offset,
                                                    int length)
Like calledPartyBCDToString, but field does not start with a TOA byte. For example: SIM ADN extension fields


networkPortionToCalledPartyBCD

public static byte[] networkPortionToCalledPartyBCD(String s)
Note: calls extractNetworkPortion(), so do not use for SIM EF[ADN] style records Exceptions thrown if extractNetworkPortion(s).length() == 0


isWellFormedSmsAddress

public 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.


isGlobalPhoneNumber

public static boolean isGlobalPhoneNumber(String phoneNumber)

networkPortionToCalledPartyBCDWithLength

public static byte[] networkPortionToCalledPartyBCDWithLength(String s)
Same as networkPortionToCalledPartyBCD(java.lang.String), but includes a one-byte length prefix.


numberToCalledPartyBCD

public static byte[] numberToCalledPartyBCD(String number)
Convert a dialing number to BCD byte array

Parameters:
number - dialing number string if the dialing number starts with '+', set to internationl TOA
Returns:
BCD byte array

formatNumber

public static String formatNumber(String source)
Breaks the given number down and formats it according to the rules for the country the number is from.

Parameters:
source - the phone number to format
Returns:
a locally acceptable formatting of the input, or the raw input if formatting rules aren't known for the number

getFormatTypeForLocale

public static int getFormatTypeForLocale(Locale locale)
Returns the phone number formatting type for the given locale.

Parameters:
locale - The locale of interest, usually Locale.getDefault()
Returns:
the formatting type for the given locale, or FORMAT_UNKNOWN if the formatting rules are not known for the given locale

formatNumber

public static void formatNumber(Editable text,
                                int defaultFormattingType)
Formats a phone number in-place. Currently only supports NANP formatting.

Parameters:
text - The number to be formatted, will be modified with the formatting
defaultFormattingType - The default formatting rules to apply if the number does not begin with +

formatNanpNumber

public static void formatNanpNumber(Editable text)
Formats a phone number in-place using the NANP formatting rules. Numbers will be formatted as:

xxx-xxxx xxx-xxx-xxxx 1-xxx-xxx-xxxx +1-xxx-xxx-xxxx

Parameters:
text - the number to be formatted, will be modified with the formatting

isEmergencyNumber

public static boolean isEmergencyNumber(String number)
isEmergencyNumber: checks a given number against the list of emergency numbers provided by the RIL and SIM card.

Parameters:
number - the number to look up.
Returns:
if the number is in the list of emergency numbers listed in the ril / sim, then return true, otherwise false.

convertKeypadLettersToDigits

public static String convertKeypadLettersToDigits(String input)
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.

Returns:
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".

Build 1.0_r1(from source)

Please submit a feedback, bug or feature